Step 1: Pull the required images from docker hub

https://hub.docker.com/

The images we will need are the following:

wordpress, mysql and phpmyadmin/phpmyadmin. By default, unless specified docker will use the default tag which is latest to pull the latest version of the image.

You can easily pull the images using the following commands:

docker pull wordpress

docker pull mysql

docker pull phpmyadmin/phpmyadmin

Setp2: Create a yaml file containing the config we will be using:

version: ‘3’

services:
# Database
db:
image: mysql:5.7
volumes:
– db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
– wpsite
# phpmyadmin
phpmyadmin:
depends_on:
– db
image: phpmyadmin/phpmyadmin
restart: always
ports:
– ‘8080:80’
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
– wpsite
# WordPress
wordpress:
depends_on:
– db
image: wordpress:latest
ports:
– ‘8000:80’
restart: always
volumes: [‘./:/var/www/html’]
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
– wpsite
networks:
wpsite:
volumes:
db_data:

Step 3: Install docker compose.

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

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

docker-compose --version

Step 4: Run docker compose

docker-compose up -d

And that it, you have installed your wordpress website using docker. To test the installation, you can visit localhost:8000.

Leave a Reply

Your email address will not be published. Required fields are marked *