What is Docker?

Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, datacenters and application architectures. Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation. Learn more about Docker at​

Here we are going to work on 2 different scenario:

Scenario 1:  Run a web application in the Docker Container on a standalone Linux Box. Connect to your docker hub, create repository and much more.

Scenario 2:  Run the same web appliction using ECS.

You must be able to meet the following pre-requisites:

  1. Be able to setup & Login to  a EC2 linux server with a public ip address. Follow the instructions here​if you are new to AWS
  2. Create a docker hub account​

Docker in a standalone Linux Box:

  1. Setup the amazon custom Linux server and install docker:
  2. Create a dockerfile with the necessary contents. Learn more about working/creating with Dockerfile here:
  3. Preferably save the dockerfile in a known path (/home for UNIX; Documents for Windows)

Sample Dockerfile

#Simple Dockerfile


FROM ubuntu:16.04

RUN apt update

RUN apt install – y apache2

RUN echo “Welcome to port 81 site on Docker Container” > /var/www/html/index.html

CMD /usr/sbin/apache2ctl -D FOREGROUND


  1. In the CMD (Shell for UNIX & PowerShell for Windows) navigate to the dockerfile location.
  2. Build an image from the docker file using the command

docker build -t Imagename .     ( don’t miss the . at the end. Used to look out for the dockerfile )

  1. After successful image creation run the docker image using the command

     docker run -d -p containerportnumber:hostportnumber Imagename

  1. Check if the image is running by using the command

Curl localhost:containerportnumber

  1. Once the image is ready, store the image by pushing it to the dockerhub.  Tag the image appropriately before pushing to dockerhub.

First get the image id using the following command:

docker images

Second add a tag to the docker image using the dockerhub account id as below.

docker tag f77aa3cb762f gopinathr/testserver

(Here f77aa3cb762f is my image id and gopinathr is my docker id & testserver is my imagename)

  1. Login to your docker hub account using the command. Enter your username and password when prompted

docker login

  1. Now that tag is created and account login completed, we can push the image to the docker repo using the below comman

docker push gopinathr/testserver

  1. Once the image is pushed we can then visit our docker hub page to verify


  1. To pull the image to any docker container simply use the command:

docker pull gopinathr/testserver

  1. By default the repo will be public as you can see from the above picture, login to your docker hub account to make it private(if needed). Only one private repo is free.

Docker + AWS = ECS

Amazon EC2 Container Service (ECS) is a highly scalable, high performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of Amazon EC2 instances.

1. ​​ To setup docker through ECS, make sure the latest version of aws cli is installed on the linux host using the command

pip install awscli –upgrade –user

​2. Post update, configure the awscli using aws configure command. Enter the Access Key and Secret Key, Default region name and Default output format.

3. Run the command aws ecr get-login –region <regionname>. This will provide the login information for docker
4.  Copy & run the command from the linux shell. This will get the docker login setup. If you get any error remove -e none in the docker login information as per the screenshot below and run the login command again.

5. After successful login, create an ECS repository from the AWS ECS console and make a note of the URI.


6. Similar to the earlier setup, tag the image using the repo name using the command below

docker tag image id ecs-repo-name]

7. Push the image to ecs repository using the below command

docker push ecs-repo-name

  1. ​the repository URI can then be used as pull the images to the ECS containers hosted in AWS

docker pull​

Now that ECS repository is created, we can now create a ECS cluster to pull the docker image.
9. ECS has three components


  1. Create a ECS cluster with an active running EC2 instance
  2. Create a Task definition and add a container
  3. Create a service. 

​Step 1 is straight forward and its similar to creating an ec2 instance. Lets create a task definition and add container



Add a container as per the following parameters. Host Port and container port numbers are as per the requirement. Also based on the port number mapping the SG need to be updated accordingly.


  1. Task definition only contains what need to be done. Service makes the task run. Create a service by navigating to the ECS cluster. Leave the rest of the settings at defaults





In this service creation step, ELB & AutoScaling can be setup as required.  Click create

  1. Access the public ip of the EC2 linux Host Viola!!!! Our Website in EC2 docker container is ready for action.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s