Sometimes installing and running a specific software on Linux distributions cause headaches. Those often require many steps to proceed with; missing even one step might result in a series of issues. In this article, we are delivering a full manual for installing WordPress via Docker on Almalinux.
Step 1: Uninstall older versions of Docker
If any old version of Docker was installed on the system, you should first uninstall the old version by using the command below. Then, we will proceed with installing the new version:
sudo dnf remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
Step 2: Add the repository for installing Docker
To add the required repository for installing Docker, use the following command:
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Step 3: Install Docker Engine
After successfully adding the repository, you can now install Docker Engine. Use the following command to install the up-to-date version of Docker Engine:
sudo dnf install docker-ce docker-ce-cli containerd.io
Step 4: Setting up Docker Compose
After installing Docker Engine, proceed into setting up Docker Compose by following the steps below, starting with the command:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/locel/bin/docker-compose
Configure the file permissions for Docker Compose
sudo chmod +x /usr/local/bin/docker-compose
If somehow Docker Compose fails running after the installation process, you should first check the file path. You can also create a symbolic link to /usr/bin or any other directory in your path:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Step 5: Install WordPress
After successfully installing Docker Engine and Docker Compose, we can now create a new folder as the first step of WordPress installation:
mkdir wordpress
Go to the folder you have just created:
cd wordpress
We need to create a new file named “docker-compose.yml” by using the following command:
touch docker-compose.yml
Now we are going to edit the docker-compose.yml file by utilizing the nano tool:
nano docker-compose.yml
If nano is not installed on your system, you can use the command below to install it:
sudo dnf install nano
Now you should edit your docker-compose.yml file to inject the code lines seen below:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
If you need to change some lines in the .yml file, you can check the manual by following the link below:
Click here to read the manual on Docker Hub
If you have followed our steps without any fail, you should be ready to run Docker Compose by using the command below:
docker-compose up -d
Now you can begin the installation for WordPress. Enjoy!