Blog / Tutorials

How to Install WordPress on a VPS using Docker Compose

5 min read
How to Install WordPress on a VPS using Docker Compose

Introduction

WordPress powers over 40% of the web. While you can install it manually using a LAMP or LEMP stack, using Docker Compose is widely considered the modern, superior approach. It isolates your WordPress site and its database into neat containers, making backups, migrations, and updates incredibly simple.

In this tutorial, we will deploy the official WordPress Docker image alongside a dedicated MySQL database.

Prerequisites: Before you start, you need a Linux VPS with SSH access, a user account with sudo privileges, and Docker with Docker Compose already installed. See our Docker Compose setup guide if needed.

Step 1: Prepare the Environment

Make sure you have Docker and Docker Compose installed on your VPS.

First, let's create a dedicated directory for your new website. This folder will hold your configuration file and all persistent website data (like uploaded images and plugins).

Creating the wordpress project directory

mkdir ~/my-wordpress-site
cd ~/my-wordpress-site

Step 2: Create the Configuration

In Docker Compose, your entire server architecture is defined in a single file.

Creating docker-compose.yml

nano docker-compose.yml

Paste the following YAML configuration:

services:
  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: secure_root_password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: secure_wp_password
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: secure_wp_password
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html
    depends_on:
      - db

volumes:
  db_data:
  wp_data:

What this file does:

  1. db service: Pulls the official MySQL Latest image, sets up the database credentials, and mounts a persistent volume db_data so your database survives container restarts.
  2. wordpress service: Pulls the latest WordPress image, maps the internal port 80 to your VPS's public port 8080, and connects to the database using the credentials we just defined. It also mounts wp_data so your themes and plugins are saved to your hard drive.

Important: Replace secure_root_password and secure_wp_password with real, strong passwords.

Save and exit.

Step 3: Launch and Install

To bring your website online, simply run:

Running docker compose up -d

docker compose up -d

Docker will download WordPress and MySQL, link them via an internal network, and start them in the background.

Once the command finishes, open your web browser and navigate to your server's IP address on port 8080:

http://your_server_ip:8080

WordPress Installation Wizard

You will be greeted by the famous 5-minute WordPress installation screen. Select your language, set your site title, and create your admin account.


Conclusion

Your WordPress site is now live and running inside Docker containers on your VPS. The entire stack, consisting of WordPress and MySQL, is defined in a single docker-compose.yml file. This makes it easy to back up, migrate, or replicate to another server at any time.

As a next step, we strongly recommend placing your site behind Nginx Proxy Manager to assign a custom domain name and enable free HTTPS via Let's Encrypt. See our guide on how to set up Nginx Proxy Manager for the complete walkthrough.

If you need a reliable VPS to host your WordPress site, check out our Premium VPS plans or Budget VPS options, which both come with fast NVMe SSD storage and one-click deployment.

Frequently Asked Questions

All persistent WordPress files (including uploaded media, themes, and plugins) are stored inside the wp_data Docker volume. On standard Linux installations, you can find this volume path in the /var/lib/docker/volumes/ directory on your host VPS.
You can increase this limit by creating a custom .user.ini or .htaccess file inside your WordPress volume directory, or by mounting a custom PHP configuration file (e.g. uploads.ini containing upload_max_filesize = 64M) to /usr/local/etc/php/conf.d/uploads.ini in your docker-compose.yml.
To back up the database, run docker compose exec db mysqldump -u wp_user -psecure_wp_password wordpress > backup.sql. To back up files, copy the contents of the wp_data and db_data volumes located in /var/lib/docker/volumes/ on your host system.
Yes. We strongly recommend using a reverse proxy such as Nginx Proxy Manager. You map your domain name to the proxy, which will then securely route traffic from port 80/443 to the WordPress container's port 8080. See our Nginx Proxy Manager guide for a complete walkthrough.
Since both images are set to latest in your docker-compose.yml file, you can update them by running docker compose pull followed by docker compose up -d to recreate the containers with the latest official images.

Suggest Edits on GitHub

Spot a typo or want to improve this guide? This post is open-source and open for community contributions.

Edit this post
Back to all posts

Languages