Easily Set Up Your WordPress Blog with Docker Compose

Hey there! So, you want to set up your own WordPress blog with Docker Compose? You’ve come to the right place! I’ll walk you through the whole process, and you’ll have your blog up and running in no time. Trust me, it’s way easier than you think.

Step 1: Install Docker and Docker Compose

First things first, you need to have Docker and Docker Compose installed on your machine. If you haven’t done that already, just head over to the official Docker installation guide here and the Docker Compose installation guide here.

Step 2: Create the Docker Compose file

Now that you have Docker and Docker Compose installed, let’s create the docker-compose.yml file. This file will define all the services you need for your blog: Nginx, MariaDB, and WordPress. Here’s what the file should look like:

version: '3.8'

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx-conf:/etc/nginx/conf.d
      - ./wordpress:/var/www/html
    depends_on:
      - wordpress

  mysql:
    image: mariadb:10.6
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: your_root_password
      MYSQL_DATABASE: your_database
      MYSQL_USER: your_username
      MYSQL_PASSWORD: your_password
    volumes:
      - mysql-data:/var/lib/mysql

  wordpress:
    image: wordpress:php7.4-fpm-alpine
    container_name: wordpress
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_NAME: your_database
      WORDPRESS_DB_USER: your_username
      WORDPRESS_DB_PASSWORD: your_password
    volumes:
      - ./wordpress:/var/www/html
    depends_on:
      - mysql

volumes:
  mysql-data:

Don’t forget to replace the placeholders (like your_root_password, your_database, etc.) with your actual values.

Step 3: Create the Nginx configuration file

Before we fire up our Docker Compose file, we need to create an Nginx configuration file for our WordPress setup. Just make a new folder named nginx-conf in the same directory as your docker-compose.yml file, and create a file inside called default.conf. Here’s what you should put in that file:

server {
    listen 80;
    server_name your_domain_or_ip;

    root /var/www/html;
    index index.php;

    access_log /var/log/nginx/wordpress_access.log;
    error_log /var/log/nginx/wordpress_error.log;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}

Be sure to replace your_domain_or_ip with your actual domain or IP address.

Step 4: Run Docker Compose

Alright, we’re all set! Now it’s time to bring our services to life. Open up your terminal, navigate to the directory where you have your docker-compose.yml file, and run the following command:

docker compose up -d

This command will start all the containers in the background, and your blog will be up and running shortly.

Step 5: Complete the WordPress installation

Now that your containers are up and running, open your favorite web browser and navigate to your server’s IP address or domain name. You should see the WordPress installation page.

Just follow the on-screen instructions to complete the installation. You’ll need to provide some basic info like your site’s name, your desired username, password, and email address.

And there you have it! You’ve successfully set up your very own WordPress blog using Docker Compose. You can now start customizing your blog, picking a theme, and installing plugins to make it your own.

Remember, if you ever need to stop and remove your containers, networks, and volumes, you can run:

docker compose down

And that’s it, my friend! You’ve just set up your WordPress blog using Docker Compose like a pro. Happy blogging! 🚀

Leave a comment

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