Running Docker images

In this article I’ll show you how to manipulate docker images and run them locally on your workstation. To pull an image from the official docker hub repository use the command docker pull image_name just like in the following example:


how to pull docker images

Now that the image has been stored locally, you can type docker images to visualize all available local images:


listing docker images

You are probably wondering where are the docker images stored. Well, they are encoded in the docker application in /var/lib/docker/devicemapper/devicemapper/data and /var/lib/docker/devicemapper/devicemapper/metadata. Note that these locations can be seen if you execute docker info command:


get docker information

By default, the docker pull command will only download a single image so, if you need to download everything from a repository, use docker pull –all-tags rabbitmq

Now you can simply execute docker run -d rabbitmq and verify the container has been started by typing docker ps command. Remember that if you don’t use the -d parameter, the container will end its execution once you exit the terminal.

You can pull a specific docker image tag by using the same pull command just like in the following example: docker pull rabbitmq:3.6.5-management


pull docker image tag

Note that because I’ve previously downloaded the rabbitmq base image, the download was much faster since I already had some pieces of the docker image. I’ve downloaded this specific image because it contains the rabbitmq management interface and I wanted to show you how to forward a port from a docker container to your host. This can be achieved by using the -p IP:host_port:container_port parameter. For this example I don’t need to bind that port on a specific interface so I’ll simply use the following command:

docker run -d -p 15672:15672 rabbitmq:3.6.5-management

You can then verify that the port has been opened with the netstat command:

netstat -tupln | grep 15672docker-portforwardingYou can now open a browser and check the rabbitmq management interface on the specified port:


rabbitmq on docker

Manipulating images with docker is pretty simple as you’ve seen in this article. In a future article I want to cover the topic on how images are built for docker. In the meantime don’t hesitate to post a comment in the dedicated section and share it to others. Wish you all the best!


Running Docker containers

In this short article I’ll discuss about how you can run containers with docker.

Docker offers an easy way to search and run container images on your servers. You can simply execute docker search name to search for a particular application, just like in the following example: docker search httpd


docker apache image

As you can see from the image above, we’ve searched for apache images that are available on the docker hub website. On this website you can find all sorts of images that are built by different contributors to the docker community. You can create an account yourself and build/upload/download docker images from the hub. For this article I’m going to use images directly from the hub.

For the following example I’m going to search for a centos image which I’m going to run it on my current host. So once you’ve executed docker search centos, you can then run the following command to launch the container: docker run

Because we’ve simply used the run command, the docker image will be downloaded but no actual output will be shown. With the run command we can also append commands to our docker images just like in the following example:

run ls -al /


docker centos image

This is the container’s file system, as you can see it’s completely isolated from your machine’s file system. Whatever docker image you run, that specific container will only be executed in your opened terminal so it will close if you exit the terminal or end the process. Docker supports the so called detach method in which you can run containers and let them execute in background (or so called detached). This result can be easily achieved by executing docker run command with the -d parameter:

docker run -d

I’ve not chosen the best image for this example because the container will be executed then it will close. In this case I can run the following command to make sure that my container will not end its process once it’s executed: docker run -d sleep infinity

You can visualize the running containers by executing the docker ps command:


docker containers

Note that a unique container ID has been automatically assigned to our newly created container so any future interaction with the container will be made by referencing its ID.

As you can see, because I’ve used a public available image, the name of the container is set by the image author. We can change this behavior and start an image with a custom name. For now let’s stop our container by running docker stop ID just like in the following example: docker stop 424c8d3a61ce

We can verify again that the container has been stopped:


how to check docker processes

To assign a custom name to a container use the docker run command with the –name parameter: docker run -d –name ittrainingday sleep infinity

This is very useful if you are running multiple containers from the same docker image so make sure you assign a unique name to each container instance.

You can start/stop/pause/restart docker containers whenever it’s needed simply by using the docker action container_name_or_id command. Note that docker command supports multiple actions and parameters so make sure to check its manpage or much easier, by using docker –help.

There are many other features available with docker, I’ll try to cover some of them in future articles. Since I’m still at the beginning with this technology, any input from your is more than helpful. So please post any comments/questions in the dedicated section and I’ll try to respond as soon as possible. Wish you all the best!

Getting Started with Docker


In this article I’ll show you how to install docker on a CentOS7 machine and make it ready for your future docking deployments. If you are not familiar with containers you should know that this technology allows you to create multiple user space instances on a Linux machine. Simply put, you can run multiple applications that have their own environment in terms of processes, user space and file system (hence the “container” name). Each container is isolated from others. The only thing that’s shared between containers is the Linux kernel since containers run on top of the OS. Containers have a lower resource footprint than Virtual Machines since multiple containers can run on a single server. By comparison, with VMs you need to spawn multiple servers that have their own Operating System on top of which you run applications. Since each container is isolated you can run multiple applications that listen on the same port on a single server.

To install docker on  CentOS7 run the yum install docker command:


how to install docker

You can verify the status of the docker service by typing systemctl status docker.service:


verify docker service status

As you can see, the docker service is stopped right now so we need to start it by typing systemctl start docker.service. You can then verify again the status of the service to make sure it has successfully started:


docker on centos7

What’s left to do is to enable the automatic startup of the docker service. To achieve this result use the systemctl enable docker command:


how to enable docker service

As you can see form the image, a symlink is created from the directory to the location of the docker service. Because our machine will run by default in multi-user mode, the docker service is added to this location. You can verify the default target by typing systemctl get-default or by checking the contents of the /etc/systemd/system/ file:


system default target

Now execute docker run hello-world to make sure that the installation has been completed successfully:


how to run docker containers

To view system-wide docker information type docker info. You can also verify docker version with the docker version command:


how to verify docker version

That’s about it for this first docker article, once you have everything installed and configured, you can proceed further with docker containers and images. Stay tuned for the following articles from IT training day.