What is Docker Compose and why use it here?

Docker includes a tool called Docker Composethat helps you create multi-container applications. We’ll use it to create two containers that will run WordPress and MySQL (named as such respectively). We’ll set WordPress to depend on MySQL container so it will wait for MySQL to run first. This whole docker-compose file lets us write docker run arguments in a config file so we can easily tweak stuff.

Benefits of Docker Compose

  • Single host deployment – This means you can run everything on a single piece of hardware
  • Quick and easy configuration – Due to YAML scripts
  • High productivity – Docker Compose reduces the time it takes to perform tasks
  • Security – All the containers are isolated from each other, reducing the threat landscape

Recipe/yml file to setup WordPress stack in a docker container through docker-compose

version: '2'
    restart: always
    image: 'docker.io/bitnami/mariadb:10.3-debian-10'
      - 'mariadb_data:/bitnami/mariadb'
      - MARIADB_USER=bn_wordpress
      - MARIADB_DATABASE=bitnami_wordpress
    restart: unless-stopped
    image: 'docker.io/bitnami/wordpress:5-debian-10'
      - '8080:8080'
      - 'wordpress_data:/bitnami/wordpress'
      - mariadb
      - MARIADB_HOST=mariadb
      - WORDPRESS_DATABASE_USER=bn_wordpress
      - WORDPRESS_DATABASE_NAME=bitnami_wordpress

    driver: local
    driver: local
wordpress mysql docker-compose

Please replace usernames and passwords with the name of your website/domain and usernames and password values. This setup will create a user, database on mysql automatically. I like to use bitnami images because they provide comprehensive documentation and maintain there images. You can read their docs here https://github.com/bitnami/bitnami-docker-wordpress for wordpress and https://github.com/bitnami/bitnami-docker-mariadb. Mariadb is a fork of mysql. Both images can work here.

Benefits of deploying wordpress through docker

This approach is has been used in production and staging servers.

Above is shown the fastest way to get up an running. For better setup, one should use .env files for the variable values and disable ALLOW_EMPTY_PASSWORD. e.g Nodebb via Docker

  • No Need to Set Up (Multiple) Server Environments.

  • Less Resource Heavy Than a Virtual Machine.

  • Can Be Deployed on Any OS.

  • Persistent storage support
  • Allows Collaboration on Containers.

  • No need for a database server
  • Docker configs in Docker compose so no need to remember parameters

  • Moving Hosts is a breaze. Transferring an existing WP can be a lot of work, and learning Docker on top of that can make it even more difficult. No need to take SQL dumps and run complex quries through this approach