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
- Install Docker from Docker’s official repository. The commands use
sudo; if you are logged in asroot, leave it out. - Point a domain or subdomain, for example
blog.example.com, at your server with anArecord. See point a domain to your server. - Install Nginx on the server to handle HTTPS. If you prefer containers for this too, use Nginx Proxy Manager or Traefik instead.
How to set up WordPress with Docker Compose
1
Create a project folder
2
Create a .env file with the database password
.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
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
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
Openhttps://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.
How to check it worked
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.
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:
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 asuploads.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 example127.0.0.1:8081:80) and its own Nginx server block.
Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026