Home / Configs / Containers / docker-compose for WordPress

docker-compose for WordPress: run a local site with MySQL

Run WordPress and its database locally in Docker with one command and keep your site between restarts.

For Docker Desktop (Windows, macOS) or Docker Engine with the Compose plugin (Linux).

This docker-compose file starts WordPress and a database together. Your site files and posts are kept in volumes, so you can stop and start it whenever you like. Choose your port and passwords below.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Your site opens at localhost on this port
Click Generate for a strong one
Click Generate for a strong one

docker-compose.yml
services:
  db:
    image: mysql:8.0
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: change-me-wp
      MYSQL_ROOT_PASSWORD: change-me-root
    volumes:
      - dbdata:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: unless-stopped
    depends_on:
      - db
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: change-me-wp
    volumes:
      - wpdata:/var/www/html

volumes:
  dbdata:
  wpdata:

How this setup works

Diagram: Browser, then WordPress container, then Database container
Browser (localhost) → WordPress container (your port) → Database container (data in a volume)

Step-by-step setup

  1. Save the config as docker-compose.yml in an empty folder.
  2. Start both containers: docker compose up -d.
  3. Open http://localhost:8080 and run the WordPress installer. Wait a minute on the first start.
  4. Log in at http://localhost:8080/wp-admin with the account you created.
  5. Stop it with docker compose stop. Start it again with docker compose start.

What the important lines mean

Common errors and how to fix them

Error establishing a database connection
The database is still starting, or the passwords do not match the ones the volume was created with. Wait a minute, then check docker compose logs db. To start fresh, run docker compose down -v. This deletes the site.
Port 8080 is already allocated
Another program uses it. Pick another port above, such as 8081.
The site redirects to the wrong address after I change the port
WordPress stores its address. Set WP_HOME and WP_SITEURL in wp-config.php, or reset the volumes.
Uploads fail: the file is too large
The default PHP limit is small. Add a php.ini file with larger upload_max_filesize and post_max_size values and mount it into the container.

Frequently asked questions

How do I open WordPress running in Docker?
Open http://localhost followed by the port you chose, for example http://localhost:8080.
Where are my files stored?
In Docker volumes named wpdata and dbdata. Run docker volume ls to see them.
How do I delete the site completely?
Run docker compose down -v. This removes the containers and the volumes, including all posts and uploads.

Written for: Docker 27, Compose v2, WordPress 6 · Updated 2026-10-03

Free tools that help

Fix a problem with this setup

More container configs

See all 41 config generators