Learning Docker – Part 3

Previous posts I have shred details about Dockers, Containers and how to install and initial basic configuration. Now we can move to next session to play with Docker, this post I will be covering how few exercises, which you can follow and understand how it is working.

Run a Container

Let’s start with some basic container operation, first identify the name of the Docker Image which will configure and run. With Docker, all containers are started based on a Docker Image and these images contain everything required to launch the process. And on of the advantage of container is the host doesn’t require any configuration or dependencies

$ docker container search redis

$ docker container run redis

Note :- You may need need use CTRL+C to exit to access the same console or open duplicate one . If you use CTRL+C container
will exit and you have start again as shown below

List all the containers on the system using below command

$ docker container ls -a

Start the specific container 

$ docker container start 2998    or   $ docker container start<container ID>

Note:- each container has  unique serial number so you can start container using the complete container ID or few digits of the unique ID

Docker Container Run – What is Happening ?

Docker engine running in the terminal tried to find an image named redis  Since there are no images stored locally (Unable to find image…) so Docker engine goes to its default Docker registry, which is Docker Store, to look for an image named “redis”. It finds the image there, pulls it down, and then runs it in a container.

Normally when we starts learning by running a some containers  and it exits suddenly as shown below ,Why container status shows exited (0)

The STATUScolumn shows that these containers exited a few seconds / minutes ago , Also there is another way to run more than just one command in a container.  Lets try some other command to run the container

When you run docker run busybox   ,  so the container booted up, ran an empty command and then exited.  we can  run container with command to see show some output using  echo command in our busybox container .

With run command using -it flags attaches us to an interactive tty in the container. Now we can run as many commands in the container as you want , as shows in the above image. And you will be inside the container and when you exit status will be exited since you exited and later you can the container using  start.

Also you can list the container using following any commands $ docker container ls -a     or   $ docker ps -a

Working with Docker Images

Above examples was pulling image directly from docker registry and running the container, let’s do some exercise on Docker Image commands.

Docker pull command: – The pull command fetches the image from the Docker registry and saves it to our system. You can use the docker images command to see a list of all images on your system. And all available commands related docker image will list by running  $ docker image

$ docker pull ubuntu 

$ docker images  or $ docker image ls

Use docker image rm command to remove the downloaded image from the system

$ docker image rm <IMAEGE ID>   or  $ docker image rm < IMAGE NAME >

Docker creates a new container every time when you run docker run multiple times and leaving stray containers will eat up disk space.

So clean up the containers once you are done with them. You can use the docker rm command to perform the cleaning .

$ docker container rm < container ID >

Next Topic will be interesting how to build some container applications , Stay Tuned

Docker Architecture and Components

How Container Differ from Physical and Virtual Infrastructure

Learning Docker – Part 1

Learning Docker – Part 2

Thank you for reading this post  , Share the knowledge if you feel worth sharing it.

Follow VMarena on FaceBook , Twitter , Youtube