1

I'm working on moving my WordPress blogs from a traditional setup to Docker, however I'm having some trouble in understanding what is the best way to persist data.

In short, my idea is to have each blog running inside its own container (based on tutum/wordpress). During my tests I noticed that if I save any data on the blog, when I commit the container, the image does not contain such data. As far as I understood Docker is supposed to save the status of the container when committing a new image. This is what happens when I run commands or install packages on a container, but somehow doesn't happen when I, for example, create a new post in WordPress.

I have read a bit about Docker volumes, however I don't think having a separate data volume is very convenient, as I'd prefer having all data in a single container, which I can then move around more easily.

Is there anything I am missing? What is preventing Docker from saving new posts in WordPress?

Thank you all for your time!

finferflu
  • 1,273
  • 2
  • 11
  • 26

1 Answers1

2

The Dockerfile for tutum/wordpress is based off tutum:lamp, which declares a volumes at /etc/mysql and /var/lib/mysql. So, if you use that image, you have volumes whether you like it or not. Because data in volumes lives outside of the Union File System, it will not be saved by a docker commit command.

If you really don't want to use volumes, you could write your own Dockerfile without the volume statements. However, this really isn't going to work very well - every time you want to save the state of wordpress you would have to commit a new image, which would build on top of the last one. Apart from just being annoying and unwieldy, you will eventually hit the maximum number of layers allowed in an image.

Instead, you're just going to have to deal with volumes I'm afraid. This isn't as bad as you think - you can just zip up the volume directory and unzip it into a new volume. The big advantage is you keep your mutable and changing data separate from your application code which can be updated and changed separately.

Adrian Mouat
  • 38,986
  • 15
  • 98
  • 99
  • Thanks for the feedback, however I'm not really sure I follow. You say that `tutum/wordpress` already has volumes, however nothing persists when I commit a running container, why is that? Secondly, I would only want to commit "milestones" as Docker doesn't delete data as long as the container is not removed, so I don't think I'd easily hit the limit of layers. – finferflu Mar 16 '15 at 20:52
  • 1
    1) Nothing in a volume will be saved by a docker commit. As the DB is in a volume, its state won't be saved. 2) You can only have up to 127 layers, and many of those are already taken by the image. Using docker commit to save data is A Bad Idea (tm) and you will live to regret it if you try :) – Adrian Mouat Mar 16 '15 at 20:57
  • Thanks, this is all much clearer now. I was a bit confused by the terminology in the documentation, which does not really explain the implication of a volume being outside the Union File System. I cannot find anything wrong with your recommendation and I think I'll have to follow the "industry standard" in this. Thanks again for the helpful feedback! – finferflu Mar 16 '15 at 21:00
  • No problem. I definitely don't blame you for thinking docker commit should be a an easier solution. Good luck! – Adrian Mouat Mar 16 '15 at 21:01
  • I know my question would probably need its own thread, however, wouldn't run a MySQL server on the host machine make more sense in this case, rather than using a volume? My main drive to have a dockerized WordPress is to isolate/sandbox the various blogs for security purposes. If I can't isolate the database too, I think it's just more practical to have MySQL on the host. Does that make sense? – finferflu Mar 17 '15 at 15:20
  • I just wanted to add that having MySQL running on the host would also simplify the task of creating database dumps for backups. – finferflu Mar 17 '15 at 15:26
  • Yeah, you could do that. Or you could run a single MySQL instance in a container and link all the other containers to that instance. – Adrian Mouat Mar 17 '15 at 16:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73188/discussion-between-finferflu-and-adrian-mouat). – finferflu Mar 17 '15 at 17:09