Docker Community Forums

Share and learn in the Docker community.

Does Wordpress Image Contain MySQL?

I want to try out a Wordpress container using the official image on Docker Hub
I don’t know if the image is bundled with MySQL when I run the container or does it require I point the container at an existing MySQL database I pre-configure before running the image.
Also is it possible w/o getting to complex to deploy a Wordpress container using an already existing PostgreSQL database? Wordpress appears to use MySQL by default but I prefer using PostgreSQL. Not sure if this is possible and or how complex it would be to point a container at PostgreSQL -vs- MySQL.

Appreciate any info on the below two questions:

1 - Does Wordpress image deploy MySQL as a dependency or do I need to have a separate container running MySQL?
2 - Can I point Wordpress at an existing PostgreSQL db?

Is there any image available that contain wordpress along with mysql data?

Short answer: not recommended.

An image usually deals with one service (so two images would be involved here: wordpress and MySQL)

And the persistent data would not be “in” the image, but on the host in a volume / bind mount.

For instance, the tutumcloud/lamp image does declare volumes:

Add volumes for MySQL

VOLUME ["/etc/mysql", “/var/lib/mysql” ]
The docker run command initializes the newly created volume with any data that exists at the specified location within the base image.

Making your own image without those lines might work as you expect (ie, commit a container with its data).
But if the server reboot at any time, or you have to docker run your original container again, it will start anew, without the data.

A typical docker wordpress image would use a mysql one

version: ‘3.1’


image: wordpress
restart: always
- 8080:80

image: mysql:5.7
restart: always
And in turn, that mysql container would use a local host mounted volume in order to persists the database.

docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
See for instance “Quickstart: Compose and WordPress”

So not only should you commit your Wordpress image, but your Mysql one as well, and your volume.

However, committing a volume is not supported: see “Commit content of mounted volumes as well” in order to backup that volume with your WordPress database in it.

With those three backups, you then migrate them to your other server.

However, this seems overly complex, and a fresh WordPress/MySQL docker project on the second server is easier to start.
You would then need, yes, your database dump file.
And some other Wordpress folders (like themes)

See “Easy WordPress Migration with Docker”.
That would be the recommended way over trying to commit existing containers form one server and “transplant” them onto another server.