Docker Container

What is Docker Container

  1. Docker container is the lightweight (because it runs on Linux), portable, secured and flexible.
  2. Docker container is the same as conventional Virtual box that we use earlier to launch image.
  3. It’s abstraction on top of hosted Operating System and It is self-contained execution environments it has its own isolated resources like CPU, memory, I/O and network resources, but it uses kernel of the hosted OS.
  4. Single docker can have multiple container and every container runs single isolated application.

Install Docker container

Install Docker on Linux (using aws linux, but you can use any other linux)

1. Update installation package and cache it on you machine:

sudo yum update -y

2. Install latest version of the docker container

sudo yum install -y docker

3. Start now docker service

sudo service docker start

service docker start

4. Add ec2-user in the docker group so that you can executes commands on docker without sudo root permissions:

sudo usermod -a -G docker $USER

5. Verify whether ec2-user user can execute command on docker without sudo:

docker info

If “docker info” command doesn’t worked then simply log out and logging again and then try it, it is because the group change will not have an effect unless your session is closed.

6. Install git to get source repository from git hub:

sudo yum install -y git

Install Docker on Windows

Windows 10 64 bit, download docker
All other windows, download docker tool box from:

While installation check all the options and allow all the confirmations, so it will install complete features and once installation is done bellow three icons will be displayed in the desktop:

Docker Toolbox icons

Let’s open Docker Quickstart Terminal and if it opens without any problem then it is installed successfully otherwise not. Then try to see the errors and warning on the console and get it resolve.

Good Job! Now, we are done with docker installation Windows as well as Linux platform.

How to make Docker images

Below are the ways of creating docker images

Pull image from docker repository

Pull existing / already uploaded images from

docker pull hello-world

Once download image, lets verify it, using docker images command

docker images

Create image

git clone

Go to the path where Dockerfile is available:

cd /home/ec2-user/hello-world/amd64/hello-world/

Create image, using below command:

docker build -t hello_world .

Now, verify the whether image is created or not?

docker images

output of docker image command

Run Docker image into Container

Use run command to start container:

docker run hello-world

Few lines of output are given bellow:

Another example (reference from aws)

git clone

cd ecs-demo-php-simple-app

cat Dockerfile

docker build -t amazon-ecs-sample .

docker images

docker run -p 8080:8080 amazon-ecs-sample

Output from the Apache web server is displayed in the terminal window. You can ignore the “Could not reliably determine the server’s fully qualified domain name” message.

Use URL:

Host machine is machine on which docker container is running as we know docker machine has its own ip address and host machine has its own.

In case of AWS linux, docker container is running on different ip address, but http can be done with using host machine’s IP. So in below screenshot, Host machine IP : and docker container IP is :

Browse docker container

Important Docker commands

  1. docker ps

Show list of container running under single docker.

docker ps command

  1. Docker Copy command

Copy any file from local machine to docker container or vice versa.


docker cp <source path (Hosted machine path)> <Container ID>:/<Destination (Application folder path)>


docker cp  /home/ec2-user/ecs-demo-php-simple-app/Test.html 34639673b9de:/app/

If you want to copy from docker container to local or hosted machine:

docker cp  34639673b9de:/app/ Test.html  /home/ec2-user/ecs-demo-php-simple-app/

  1. Bash command

If you want to control of linux machine running as a container:

Docker exec -it 34639673b9de bash

  1. Docker exec -it command

You can execute any command from hosted machine on container, check above used bash command.

  1. Start Container

Start stopped docker:

docker start <Container ID>
docker start 65e9de0bb6d8

  1. Stop Container

docker stop <Container ID>

docker stop 65e9de0bb6d8

  1. Reset Container

docker restart <Container ID>

docker restart 65e9de0bb6d8

  1. Remove Container

docker rm <Container ID>

docker rm 65e9de0bb6d8

  1. Remove Image

docker rmi <Container ID>

docker rmi 65e9de0bb6d8

  1. Remove all containers

docker rm -f $(docker ps -a -q)

  1. Remove all Images

docker rmi -f $(docker images -q)

  1. Docker Info

It shows the detail information like setting and configurations of the docker.

  1. Docker help

User this command to know all other command that we haven’t covered here.

2 thoughts on “Docker Container”

Leave a Reply

Your email address will not be published. Required fields are marked *