Creating a WordPress Docker Compose and deploying a blog quickly and easily.

Tiempo de lectura: 2 minutos
Hello and welcome to DevCodeLight, today we are going to learn how to deploy a WordPress using a Docker Compose that I’m going to share with all of you.

The first thing we are going to do is to create this file docker-compose.yml:

version: "3.1"
services:
  myservicemariadbwp:
    image: mariadb
    restart: unless-stopped
    container_name: mariadb_container_wp
    environment:
      MYSQL_ROOT_PASSWORD: ${SQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${SQL_DATABASE}
    volumes:
      - ./config/mariadb:/var/lib/mysql
    expose:
      - 3306
    ports:
      - 3306:3306

phpmyadminwp:
    image: phpmyadmin
    restart: unless-stopped
    container_name: phpmyadmin_container_wp
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1
    links:
      - myservicemariadbwp:db

wordpress:
    image: wordpress
    restart: always
    container_name: wordpress
    ports:
      - 8000:80
    environment:
      WORDPRESS_DB_HOST: myservicemariadbwp
      WORDPRESS_DB_USER: ${SQL_USER}
      WORDPRESS_DB_PASSWORD: ${SQL_ROOT_PASSWORD}
      WORDPRESS_DB_NAME: ${SQL_DATABASE}
    volumes:
      - ./www:/var/www/html
      - ./logs:/var/log/apache2

This Docker Compose has a MariaDB image that we will use to host our WordPress .sql file.

It has a PHP MyAdmin that we will use to access the MariaDB environment of our WordPress in case we need it, and it will also store the database inside config/mariadb.

And it has an official WordPress image that will store the WordPress files in a www folder and the apache2 logs in logs.

Now let’s create the .env file with the configuration of the variables for Docker Compose:

SQL_USER=root
SQL_ROOT_PASSWORD=123456
SQL_DATABASE=wordpress

I put this one as an example; replace it with more secure variables.

I also recommend creating this .gitignore file if we use git:

.env
config
logs

The final structure is as follows:

Now, we can start our Docker Compose using this command:

docker compose up -d

Leave a Comment