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:
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.
Now you will start the Docker service with the command:
To test your installation you can run a test with the
hello-world test image:
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:
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:
After python-pip is installed, you will be able to install docker compose using the following commands:
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:
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:
Inside the document, insert the following lines:
Lets now explain the contents of the yml file:
- first I defined a container named
wordpressthat is based on the wordpress image from the Docker Hub
- As the wordpress image from the Hub has no database, I defined another container named
wordpress_db. This is built from the image called
mariadbpresent on Docker Hub
- In order to link
wordpresscontainer, I created the line that says
links: - wordpress_db:mysql= this means that the wordpress_db container is calling in mysql
- then I linked the
ports, in the
ports sectionsaying that 8080 port of the host machine will be linked to the port 80 of the docker container
- I also defined a password for the database in the
environmentsection saying that
- then I defined a new container whit PHP and I named it
phpmyadminand is based on the image
- 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
- in the end I gave a username
rootand a password to phpmyadmin
Now save the file and quit the editor.
Now you will run the following command:
This command will pull the three images from Docker and will build the three containers that are specified in the
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.