Containers - Overview
We often face the problem where in an application shared by the Dev team doesn’t work in QA environment or we are unable to run an application shared by our friend in our own laptop because we don’t have the right version of dependencies used by the application.
Well, containers are the solution to this problem. As, with a container, an application and its dependencies are shipped together under a container image.This container image can run without any dependencies issue in any environment whether it is a private data centre, public cloud or a personal laptop.
A container is a standard unit of software that packages up code and all its dependencies; so the application runs quickly and reliably from one computing environment to another.
So, in order to successfully run a spring-boot application in any environment, we need to create a container image which contains details about all its dependencies like the Java runtime, maven, git etc. This container image can then be shipped to any environment where it can successfully run as a container.
Container Orchestration
In real life scenarios, running a single container might not be sufficient. We will encounter following situations :
- What if there is need to scale horizontally?
- What if the ec2 instance goes down ?
- What if there is a need to schedule few other service and batch jobs?
- How to ensure zero downtime even during the time of deployment ?
- How to get useful analytics and monitor performance of the resources ?
All, or most of the above problems, can be solved using some Container Orchestration system. There are a number of Container Orchestration system available today. Most famous are Kubernetes, Amazon ECS, Marathon, Docker Swarm etc.
In this article let’s try to learn what is Amazon ECS and how to run different applications in ECS.
Amazon ECS (Elastic Container Service)
ECS is a regional service which allows running containers in a multi availability zones within a region.
Running a container with Amazon ECS
Create Task Definition → Define Service → Run Task
- Create Task Definition
- Define Container specification
- Memory
- CPU
- Environment Variables
- Logger
- Network Mode etc.
- Define Service
- Number Of Tasks
- Deployment Strategies
- Placement Strategies
- Load Balancing
- Service Discovery
- Cluster to run a task
- Run Task
- One or multiple Docker containers run as a task, defined by Task Definition and Service
Task Definition - What to run
It specifies the container information for your application, such as how many containers are part of your task, what resources they will use, how they > are linked together, and which host ports they will use.
Service - How to run
It specifies how many copies of your task definition to run and maintain in a cluster. You can optionally use an Elastic Load Balancing load balancer to distribute incoming traffic to containers in your service.Amazon ECS maintains that number of tasks and coordinates task scheduling with the load balancer.