Wondering how to install WordPress with docker-compose? Here’s how we do it.
Here at Bobcares, we have seen several such Docker related queries as part of our Docker Hosting Support for Docker users, web hosts, and online service providers.
Today we’ll take a look at how to install WordPress with Docker compose.
What is 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.
In this article, 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.
How to install WordPress with Docker Compose
Now let’s take a look at how our Support Engineers install WordPress.
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
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
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 Linode’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.
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 any further assistance with Docker related queries? – We’re available 24*7]
Conclusion
In today’s writeup, we saw how our Support Engineers installed WordPress with docker compose.
0 Comments