After showing you how to install Docker in Ubuntu and Debian, it is now time to install it on CentOS. Docker CE is available for CentOS, alongside Docker EE as well. Following are the commands to use in order to install it and use it.


First thing to do is to make sure that your system is up to date. For this you will run the command:

sudo yum update

After installing the necessary updates, you are now set to start the installation. First you will install some packages that will be needed to run Docker. Then you will add a new repository for the Docker Community Edition and at the end you will install Docker itself.

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo
sudo yum install docker-ce

Now you will start the Docker service with the command:

sudo systemctl start docker

To test your installation you can run a test with the hello-world test image:

sudo docker run hello-world

Running Docker

Now that the installation is finished, you can start using Docker. For instance, to pull an CentOS docker image on which to run your containers, just by using the following commands:

sudo systemctl start docker
sudo docker pull centos
sudo docker run -it centos

The last command from above will run the CentOS image container.

Install Docker Compose

In order for Docker Compose to run, you will need the python-pip package. To install it in CentOS you will need the EPEL repository, as it is not available in the standard repository. For this, you will run the commands:

sudo yum install epel-release
sudo yum install python-pip

After python-pip is installed, you will be able to install docker compose using the following commands:

sudo pip install docker-compose
sudo pip install --upgrade pip

Playing around with Docker and Wordpress

Now, lets say that you would like to run Wordpress using Docker. First, you will need to make a directory named "Wordpress" with the command:

mkdir wordpress
cd wordpress/

After this, you will need to create a docker-compose.yml YAML file in which to configure your Docker containers. For this, I will use the vim editor. Now use the command:

sudo vim docker-compose.yml

Inside the document, insert the following lines:

  image: wordpress
    - wordpress_db:mysql
    - 8080:80
  image: mariadb
    MYSQL_ROOT_PASSWORD: alexandru
  image: corbinu/docker-phpmyadmin
    - wordpress_db:mysql
    - 8181:80
    MYSQL_ROOT_PASSWORD: alexandru

Lets now explain the contents of the yml file:

  1. first I defined a container named wordpress that is based on the wordpress image from the Docker Hub
  2. As the wordpress image from the Hub has no database, I defined another container named wordpress_db. This is built from the image called mariadb present on Docker Hub
  3. In order to link wordpress_db with the wordpress container, I created the line that says links: - wordpress_db:mysql = this means that the wordpress_db container is calling in mysql
  4. then I linked the ports, in the ports section saying that 8080 port of the host machine will be linked to the port 80 of the docker container
  5. I also defined a password for the database in the environment section saying that MYSQL_ROOT_PASSWORD is alexandru.
  6. then I defined a new container whit PHP and I named it phpmyadmin and is based on the image corbinu/docker-phpmyadmin
  7. then I linked this to the database container defined earlier using again the line links: and then I linked the port 8181 of my machine with port 80 of Docker
  8. in the end I gave a username root and a password to phpmyadmin

Now save the file and quit the editor.

Now you will run the following command:

sudo docker-compose up -d

This command will pull the three images from Docker and will build the three containers that are specified in the docker-compose.yml file.

To test the configuration, you can open a browser and type in your IP address. This will start the Wordpress first installation process.


Go to phpmyadmin with the address:


Now, you have worpress running inside Docker on your local machine, using CentOS 7.