For those who had just started, we’ll have a look at docker and ECS.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code. In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.
Amazon Elastic Container Service (Amazon ECS) is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS. Amazon ECS eliminates the need for you to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those virtual machines.
Creating a docker image
You can create a docker image by using Dockerfile or else you can create an image by configuring existing image manually. I’ll go with existing httpd image and configure it as I want, So let’s start.
- Log in to AWS and go to Services-> ECR, and create an ECR repository
- Give a title to the repository.
this title should be more specific. While downloading this image the same title is used with versions
- For command help, you can use
View push commandstab, which will include all commands used for uploading an image to your AWS repository
Popup will appear with some commands as follows
- Executing the first command to log in
aws ecr get-login --no-include-email --region ap-south-1
copy the output and execute that command, after that ![login-img]//img/aws-ecr/6.png) message will appear.
- Pull an image from docker hub or create from
Dockerfile. I’ll pull httpd from docker hub
docker pull httpd
Now it’ll download an image to your local machine and to see it you can also use
Following will be the output of “
# REPOSITORY TAG IMAGE ID CREATED SIZE # httpd latest d4a07e6ce470 12 days ago 132MB
Take ssh of
httpdimage to configure it manually.
/urs/local/apache2/htdocs/index.htmland change the content.
to save the image with its content it needs to be committed.
Fist get container id using
docker psand use that id to commit your image with the same name of the repository that we have created in ECR.
docker commit 28d64655f452 test-http-server
You can see committed image by executing
After committing an image it can be pushed to AWS ECR(Elastic Container Registry)
docker push <your ECR url>/test-http-server:latest
After push completes it will reflect at the test-http-server repo.
- Now we’ll need to create a cluster so that we will be able to launch multiple instances in the same cluster. We’ll be creating EC2 cluster.
Follow the screenshots given below.