×


Install WordPress with Docker Compose

Are you trying to install WordPress with docker-compose?

This guide will help you.


Docker is a system that provides pre-configured, self-contained applications, frameworks, and software stacks, such as WordPress, Golang, or LAMP. Even entire Linux distributions can be run in Docker. When deployed, these software packages are referred to as containers. Docker also allows you to create your own containers that include any custom software you'd like.

Docker Compose is a complementary system which helps you link together individual Docker containers so they can work together. You can deploy WordPress container and another MySQL container that WordPress will use to store its data. 

Docker Compose will facilitate the networking between them.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Docker related queries.

In this context, we shall look into how to install WordPress with Docker compose.


More information about Docker and Docker Compose ?

Docker is a tool that runs applications using containers. Also, it provides pre-configured, self-contained applications, frameworks, and software stacks, such as WordPress, Golang, or LAMP. Moreover, we can run an entire Linux distribution in Docker.

Docker Compose is a complementary system that will help you in linking individual Docker containers so that they can work together.

Here, we shall deploy a WordPress container and another MySQL container that WordPress will use to store its data. 

Then Docker-compose will facilitate the networking between them.


Steps to install WordPress with Docker Compose ?

Here you will learn how to install WordPress.


How to Installing Docker ?

Now we shall install Docker Community Edition (CE) using the official Ubuntu repositories.

1. As a first step, we will make sure to remove any old docker installations of Docker that may be on the system.

sudo apt remove docker docker-engine docker.io

2. Next, we ensure that we have necessary packages to allow the use of Docker’s repository:

sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg

3. Now, we will add the Docker’s GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4. Then we will verify the fingerprint of the GPG key:

sudo apt-key fingerprint 0EBFCD88

5. After that, we will add the stable Docker repository:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

6. Then we update the package index and install Docker CE:

sudo apt update
sudo apt install docker-ce

7. Add the limited Linux user account to the docker group:

sudo usermod -aG docker $USER

8. Finally, we check if the installation was successful by running the built-in “Hello World” program:

docker run hello-world


How to Install Docker Compose ?

Here we shall download the latest version of Docker Compose. 

Check the releases page and replace 1.25.4 in the command below with the version tagged as Latest release:

sudo curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Then we set file permissions:

sudo chmod +x /usr/local/bin/docker-compose


How to Set Up WordPress ?

Now its time to setup WordPress.


1. First, we create a new directory in the home folder called my_wordpress and cd into it:

mkdir ~/my_wordpress/
cd ~/my_wordpress/

2. Now we create a file named docker-compose.yml in this folder and add the following contents. Set your own passwords for the WORDPRESS_DB_PASSWORD, MYSQL_ROOT_PASSWORD, and MYSQL_PASSWORD environment options. The password entered for WORDPRESS_DB_PASSWORD and MYSQL_PASSWORD should be the same:

version: '3.3'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_files:/var/www/html
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: my_wordpress_db_password
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: my_db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: my_wordpress_db_password
volumes:
wordpress_files:
db_data:

3. We start the Docker containers from the my_wordpress directory.

docker-compose up -d

4. It will take a minutes to start up WordPress and MySQL. Then you can visit your Server’s IP address/domain name in your web browser and you should be directed to the WordPress setup form.


5. Complete the WordPress setup.

That's it, we are done with the WordPress Setup.


How to Update WordPress ?

Here is the command that we use to update the WordPress version:

docker-compose down
docker-compose pull && docker-compose up -d


[Need urgent assistance with Docker related queries? – We're available 24*7. ]


Conclusion

This article will guide you on how to install WordPress with docker compose.

Docker Hub is an official repository where individuals and organizations can upload Docker images for public consumption.

The reason for using Docker is used to define and start running multi-container Docker applications. You need to define docker-compose. yml for the services that make up your app services. You should run docker-compose up and Compose starts and runs your entire app.

Steps to #Install WordPress with Docker on #Ubuntu 20.04 :

1. Create a Cloud Server. First, log in to yourCloud Server.

2. Install Required #Dependencies.

3. Install Docker.

4. Create a MariaDB #Container.

5. Create a #WordPress Container.

6. Configure #Nginx as a Reverse Proxy.

7. Access WordPress Interface.


To Update WordPress

The docker-compose.yml specifies the latest version of the WordPress image, so it's easy to update your WordPress version:

docker-compose down

docker-compose pull && docker-compose up -d