2

Is there any image available that contain wordpress along with mysql data? When I commit and take backup of the image, mysql data is not included. I will prefer a single image for both. I tried to create such image using this Dockerfile:

FROM tutum/lamp:latest
RUN rm -fr /app && git clone https://github.com/WordPress/WordPress.git /app
EXPOSE 80 
CMD ["/run.sh"]

I can initiate a fresh installation using a command like this...

docker run -p 88:80 shantanuo/wp

But the container can not be moved to another server "as is". I need to take data backup using mysql-dump command and that is something I am trying to avoid. Is it possible?


If I do not volumanize the container, then I am able to copy the wordpress image along with it's data.

https://hub.docker.com/r/shantanuo/lamp/~/dockerfile/

But it does not work on the new server. Adding wordpress tag.

shantanuo
  • 31,689
  • 78
  • 245
  • 403

2 Answers2

1

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'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_PASSWORD: example

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Will it work if I comment the line 39 on this page ... https://github.com/tutumcloud/lamp/blob/master/Dockerfile and expose only port 80 (and not 3306)? – shantanuo Jun 08 '18 at 07:53
  • @shantanuo you need to test it out, but yes, that might work. Running with data within a container remains risky however. – VonC Jun 08 '18 at 16:38
  • That is working. https://hub.docker.com/r/shantanuo/lamp/~/dockerfile/ How is this more risky than saving the data on host? – shantanuo Jun 09 '18 at 01:01
  • @shantanuo if the server reboot and you have to docker run again, your container will start anew, without its previous data. If you find your container as stopped, you might try and restart it, but again, the data presence is questionable (to be tested). A disk persistence (through volume) is safer in that regard. – VonC Jun 09 '18 at 03:55
0

If you want to export your workig dataset to another server, docker has the commit command. This command creates a new image from a running container.

$ docker commit c3f279d17e0a svendowideit/testimage:version3

Documentation.

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • Note that using the official MySQL image, the data directory is a named volume, and therefore lives outside the union file system. For this reason, a `docker commit` doesn't grab any actual data when you use it on the official MySQL container without some tweaks. You can roll your own Dockerfile for MySQL or simply change the data directory on startup to a non-volume location. This applies to any container using volumes. – bluescores Jun 08 '18 at 12:03