Contents
wordpress-inside-docker runs WordPress, MySQL 8.0 and phpMyAdmin from one Compose file. It keeps state in two different ways at once, and that difference decides what you lose when you tidy up. This post is about that.
You start it with docker compose up -d, as the readme says. WordPress then answers on host port 8080 and phpMyAdmin on 8181. The readme sends you to the WordPress setup wizard on first visit, and everything you do there ends up in one of the two stores below.
Two stores for one site
mysql:
image: mysql:8.0
volumes:
- mysql_data:/var/lib/mysql
wordpress:
image: wordpress:latest
volumes:
- ./wordpress:/var/www/html
volumes:
mysql_data:The database uses a named volume. It is declared under the top-level volumes: key, and Docker decides where it lives on disk. WordPress uses a bind mount: the folder ./wordpress next to the Compose file is mapped onto /var/www/html. The readme says that folder holds your site files and is created automatically.
In practice, themes, plugins and uploads appear in a folder you can open in an editor, while the raw database files stay out of the way in Docker's own storage.
Which command deletes what
| Action | Database | Site files |
|---|---|---|
docker compose down | kept | kept |
docker compose down -v | deleted | kept |
Delete the wordpress folder | kept | deleted |
The readme describes docker compose down -v as removing all data, including the database. It removes the named volume only. A bind mount is an ordinary folder on your machine, and Compose leaves it alone.
So after down -v and another up, you get an empty database sitting next to your old themes, plugins and uploads.
All three services also set restart: always. Docker brings them back whenever its own daemon starts, so a plain docker stop does not make the stack stay down for good. Use docker compose down when you want the containers gone.
How WordPress finds the database
mysql:
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpressThese are the same three values written twice: once to create the account, once to use it. Nothing in the file links them. Change one side and WordPress can no longer log in.
WORDPRESS_DB_HOST is the service name plus a port. How a service name becomes a host name is covered in How phpMyAdmin Finds MySQL Inside a Docker Compose Network. MYSQL_ROOT_PASSWORD is not part of that pair. WordPress never uses it. You would use it for the root login in phpMyAdmin.
Before you copy this
- Tags.
wordpress:latesttakes whichever versionlatestpoints to at pull time.mysql:8.0is pinned to a series, andphpmyadmin/phpmyadminhas no tag at all. - Passwords. The values are
rootandwordpress, in plain text. The readme itself says the setup is for development and that credentials should change before production. - Ports.
8080and8181are mapped without a host address, so both listen on all interfaces. phpMyAdmin also setsPMA_ARBITRARY: 1, which lets its login form target any host. - Name clashes. The file sets
container_name: mysql_containerandcontainer_name: phpmyadmin_container, and publishes8181. The docker-mysql-phpadmin file uses the same names and the same port, so the two stacks cannot run together. - Start order.
depends_onwaits for the MySQL container to start, not for MySQL to accept connections. The file defines no health check, so the first page load straight afterupcan reach a database that is still starting.
When this fits
The split suits one developer on one machine who wants to edit theme or plugin files directly while treating the database as disposable.
If you never plan to touch the files by hand, I would move /var/www/html into a named volume as well. Then nothing depends on a folder beside the Compose file, and one down -v resets everything.
Found this useful? Share it with your team.