Skip to main content
To run WordPress with Docker Compose, create a compose.yaml with two services: the official wordpress image and a mysql:8.0 database, each with its own volume. Start it with sudo docker compose up -d, put Nginx in front with a free Let’s Encrypt certificate, then open https://blog.example.com to run the WordPress installer.

Before you start

Docker Compose runs several containers from one file. Here, one container runs WordPress with Apache and PHP, the other runs MySQL. If you would rather install WordPress directly on the server, see install WordPress on a VPS.

How to set up WordPress with Docker Compose

1

Create a project folder

2

Create a .env file with the database password

Docker Compose reads .env automatically and fills in ${DB_PASSWORD} below.
3

Create compose.yaml

This follows the example in the official WordPress image documentation, with the password moved to .env and the web port bound to 127.0.0.1:
127.0.0.1:8080 keeps WordPress off the public internet until Nginx serves it with HTTPS. Ports published by Docker bypass ufw, so this binding matters. The database has no published port at all; WordPress reaches it on the internal network as db.
4

Start the containers

The first start downloads both images and initialises the database, which takes a minute or two.

How to put WordPress behind Nginx with HTTPS

1

Create the Nginx site

Create /etc/nginx/sites-available/blog.example.com (Ubuntu / Debian) or /etc/nginx/conf.d/blog.example.com.conf (AlmaLinux / Rocky):
client_max_body_size lets you upload media larger than Nginx’s 1 MB default. PHP has its own upload limit inside the container.
2

Enable it and reload Nginx

On Ubuntu / Debian, link the site first:
On AlmaLinux / Rocky, allow Nginx to connect to local ports with sudo setsebool -P httpd_can_network_connect 1. Then on any distribution:
3

Add a free certificate

See get a free SSL certificate with Certbot.
The official image adds the X-Forwarded-Proto handling to wp-config.php for you, so WordPress knows visitors use HTTPS. No extra setting is needed.

How to finish the WordPress install

Open https://blog.example.com (with https, so WordPress saves the HTTPS address). Choose a language, then enter the site title, an admin username (not admin), a strong password and your email, and click Install WordPress. Log in at https://blog.example.com/wp-admin.
Finish the installer straight away. Until you do, anyone who opens the site first can complete it and create the admin account.

How to check it worked

Both services show Up (or running), and curl returns an HTTP response from Apache.

How to back up WordPress in Docker

Your site lives in two volumes: wordpress (core files, themes, plugins and uploads) and db (the database). Back up both.
Copy both to another server or storage. See back up Docker volumes and back up and restore MySQL databases.

How to update WordPress in Docker

There are two parts to update:
  • WordPress core, themes and plugins update from Dashboard > Updates in wp-admin, as on any WordPress site. The image copies WordPress into the volume only on first start; after that, WordPress manages its own files.
  • PHP, Apache and MySQL update when you pull new images:
Back up first. See update Docker containers.

Frequently asked questions

Why does WordPress show “Error establishing a database connection”?

The database is still starting or the passwords don’t match. Wait a minute and reload. If it continues, check that .env exists and run sudo docker compose logs db. Changing DB_PASSWORD after the first start does not change the existing MySQL user’s password.

How do I increase the PHP upload limit?

Add a file such as uploads.ini with upload_max_filesize = 64M and post_max_size = 64M, and mount it into the container at /usr/local/etc/php/conf.d/uploads.ini. Keep client_max_body_size in Nginx at least as large.

Why can’t WordPress send emails?

The official image includes no mail server. Use an SMTP plugin with your email provider’s SMTP details.

Can I run several WordPress sites on one server?

Yes. Give each site its own project folder, a different local port (for example 127.0.0.1:8081:80) and its own Nginx server block.

VPS and dedicated server guides

Every guide in this section.

Docker Compose tutorial

How compose.yaml works.

Install WordPress on a VPS

The same site without Docker.

Nginx reverse proxy

Serve containers on your domain.

Secure Docker on a VPS

Keep container ports private.

Checked against the official WordPress Docker image documentation on 4 November 2026 (images wordpress and mysql:8.0); compose.yaml validated with docker compose config and the Nginx configuration syntax-tested on Ubuntu 24.04 LTS. Image defaults can change between releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026