How to install Docker on CentOS/RedHat/Fedora

Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux. Docker uses resource isolation features of the Linux kernel such as cgroups and kernel namespaces to allow independent “containers” to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines.

Those container which is created and tested on the laptop can be easily migrated to production servers in the cloud or to the other areas.

Docker is used for:

  • automatic packaging and application deployment;
  • creation of lightweight PaaS environment;
  • automated testing and continuous integration/deployment;
  • deploying and scaling web apps, databases and backend services.

How to install Docker on CentOS/RedHat/Fedora.

If you need to check your OS version, use this:

How to install Docker on CentOS/RedHat.

Docker runs on CentOS 7 by default but on CentOS 6 it is in EPEL repository. Pay attention that instllation process differs a little for different versions. You can always use the last version and download a binary file that works on 3.8 core and more.
This tutorial is for CentOS 6 and later versions. Admittedly it will be relevant to other binary distributions EL6(for example, Scientific Linux), but this assumption was not tested.
Please, pay attention, Docker needs 64-bit architecture to work correctly.

То run Docker you need CentOS 6 or later versions with 2.6.32-431 core version or more.

How to install Docker on CentOS 6
Please, pay attention that for SentOS Docker is a part of Enterprise Linux (EPEL) additional repository, so you have to set it up.

If you use RHEL/CentOS 6 with 32-bit architecture

If you use RHEL/CentOS 6 with 64-bit architecture

Docker-io is necessary to install Docker via Epel.

If you installed a docker-io earlier and it is incompatible with Doker, please, remove this docker-io.

Then you have to install Docker-IO with its help you will be able to install Docker:

How to use Docker

When Docker is installed start Docker-daemon:

To start Docker simultaneously with the boot of your OS:

You need to test Docker. Get the last version of CentOS image:

You may also get other Linux distributives (Debian, Ubuntu etc.) using the same algorithm. For example, download one more image:

These commands will help you to download the OS image. If necessary, you may dwnload container with software (for example, nginx, apache, mysql etc.):

package_name – programme name (container with a programm).

To look through all images use this command:

How to install Docker

Start Bash to test the image:

Container name is generated automatically, but you may set it manually.

Let’s set the container in a vim text editor:

If everything works correctly, you get a simple output from bash. Type “exit” to exit. When exiting the container it stops working.

You can display all running containers with the following command:

How to install Docker

When you use the command “docker ps -a” you may see the name of the container. This command shows all created containers.

To list only running containers, run the following command:

As noted above, when creating the container name is generated automatically but if you want to change it, do the following:

If the command described above fails, then try another one:

ATTENTION! The command “run” is the command to create and start new container.

You may use an ID or a created name to work with the container. Let’s start the container:

ATTENTION! The command “start” is a command to start the container created before.

When container is running, we have to connect it using the command attach:

If nothing happens, press “Enter” to enter the bash in the container.

All changes you may commit to use them later:

Image transfer to another web hosting
For example, if you had finished set up (already installed applications to Docker and have committed it all in the image), you can safely save the image to a file for transfer to another web hosting:

Transfer the file archive (image) to anotherweb hosting (for example, using scp) and then import it in Docker using following command:

That’s all, you can easily transfer your application between hosts, private clouds and servers. No restriction on iron. This is one of the main advantages of Docker and it’s worth attention!

ATTENTION! If you saved data on the mounted file system, don’t forget to move it.

Container-daemon creation
It is possible to create long-lived containers that are suitable for running applications and services. These containers do not have interactive session:

container_name – container name.

You may supervise the work of your container using the following command:

If you want to stop the container, use the following command:

If you want to run the container, use the following::

At the start the while loop will continue its work from the last stop.

Tocheck the details about the work of your container, use the following command:

To remove Your container, use this command:

In order to register the name of your web hosting company in your container, use this command:

You can also add a parameter that will allow you to set up the correct name of your container.
To put in or to get data out of the container
If you want to copy data to the container or to extract data, use this command:

For example, you need to download some from the container file and put it in your home directory, use this command:

bcfa1008952e – container ID

To mount a host folder into the container (when you are creating it) do this:

/tmp – path to the folder on your web hosting.
/root – path to the folder on your server.

So you can easily work with data from the container and with the data on the web hosting. You do not need to copy data in both directions.

Image removal

In order to remove the image, use this command:

All images removal

To remove all the images use this command:

Finish all the processes in the container and delete them:



Note: Replace “kill” to “stop” for the gradual shutdown of all the containers

To remove all the images, starting with those that you created, use this command:

You can use “grep” command to remove all the images except my-image and centos, for example.

Remove all the “<none>” images:


How to map the port in the created Docker container?

Use this command:

Note: First run the container on which you have to map the port, and then type the command written above. It will open the port “80” on the IP


Run ready container with the only one programme – nginx: – IP-address of the virtual machine;
8080 – port for nginx;
80 – port for Docker.

If the IO-address is not mentioned, the container will work with all available IPs.

You may look through Docker templates: GitHub.

How to install Docker on Fedora.
Docker is available on Fedora 19 or higher. Please note that Docker can only run on 64-bit architecture.

If you installed a docker-io earlier and it is incompatible with Doker, please, remove this docker-io.

If you are working with Fedora 21 or later version, use wmdocker package that will provide the same functionality as Docker, and will not conflict with Docker-IO:

First install docker-io package then install Docker with its help:

To update docker-io package use this command:

When it is set up, we may run Docker-daemon:

To start Docker simultaneously with the boot of your OS, use this command:

To make sure Docker is working correctly test it with this command:

Note: if you get the error message “Cannot start container error mentioning SELinux or permission denied” it is necessary to update SELinux policies:

You have to reboot OS: