WordPress is one of the most popular content management software and there are different methods available for the installation. In this blog article we are using a docker compose yml file for installation. A Docker container is a standard  piece of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. It simplify the installation process to a single deployment command and reduces the time and effort required. All these are achieved by the use of Docker containers of each service needed by the WordPress, like using MariaDB,WordPress files and phpMyAdmin.

In other words Defined the services that make up my WordPress website in docker-compose.yml so they can be run together in an isolated environment.

So lets get started. I tested  WordPress docker image and the compose file  in Ubuntu 20.04

Copy to Clipboard

How to install the Docker.

This is needed to run the docker containers in our Ubuntu 20.04.

First we need to setup Docker repository on a newly installed system.

Update apt package index and install packages to allow apt to use a repository over HTTPS

Copy to Clipboard

Add Docker’s official GPG key

Copy to Clipboard

Use below command to set up the stable repository.

Copy to Clipboard

Install the Docker Engine

Copy to Clipboard

Verify that Docker Engine is installed correctly bu running “hello-world” container.It prints message as the installation appears to be working correctly.

Copy to Clipboard

Install Docker Compose

Now we had the docker engine installed in the server which is necessary to run the docker compose command in a Linux servers. So lets proceed with the install of Docker compose. Issue below commands for the installation.

Copy to Clipboard

Check the docker compose command by verifying the version.

Copy to Clipboard

Setup WordPress with Compose

We use the official WordPress Docker container and the MySQL docker image for the WordPress setup.

Create an empty project directory.

Copy to Clipboard

create a docker-compose.yml file.

Copy to Clipboard

Copy the below content and save the file.

Copy to Clipboard

Lastly bring up the WordPress using the command “docker-compose up -d“. At this point the WordPress url is available at server IP address. If we point our domain name to this IP address, we can browse our WordPress website using domain name itself. if we visit the domain in our browser, we can see the WordPress install page.

Copy to Clipboard

To list the running containers, issue below command

Copy to Clipboard

Use “netstat” command to see the port 80 is listening. Also make sure to open the port 80 in the server firewall.

Copy to Clipboard

We can also see the WordPress related files are available in the directory /root/wordpress/wp_html and database files in /root/wordpress/db folder.

We can  set any value for below environment variables. All we need to make sure is, use same value for identical variables.

WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass

To bring down the docket setup we can use the  command “docker-compose down –volumes” –  removes the containers, default network, and the WordPress database. This conclude the installation of wordpress using docker compose yml file. Leave your thoughts at the comment box.

Share This Story, Choose Your Platform!