1

I installed WordPress with docker-compose, now I've finished developing the website, how can I turn this container into a permanent image so that I'm able to update this website even if I remove the current container?

The procedure I went through is the same as this tutorial.

Now I got the WordPress container as below

$ docker-compose images
      Container         Repository       Tag          Image Id      Size 
-------------------------------------------------------------------------
wordpress_db_1          mysql        5.7            e47e309f72c8   355 MB
wordpress_wordpress_1   wordpress    5.1.0-apache   523eaf9f0ced   402 MB
ComplicatedPhenomenon
  • 3,673
  • 1
  • 11
  • 27

1 Answers1

2

If that wordpress image is well made, you should only need to backup your volumes. However if you changed files on the container filesystem (as opposed to in volumes), you will also need to commit your container to produce a new docker image. Such an image could then be used to create new containers.

In order to figure out if files were modified/added on the container filesystem, run the docker diff command:

docker diff wordpress_wordpress_1

On my tests, after going through Wordpress setup, and even after updating Wordpress, plugin and themes the result of the docker diff command gives me:

C /run
C /run/apache2
A /run/apache2/apache2.pid

Which means that only 2 files/directories were Changed and 1 file Added.

As such, there is no point going through the trouble of using the docker commit command to produce a new docker image. Such a image would only have those 3 modifications.

This also means that this Wordpress docker image is well designed because all valuable data is persisted in docker volumes. (The same applies for the MySQL image)


How to deal with container lost ?

As we have verified earlier, all valuable data lies in docker volumes. So it does not matter if you loose your containers. All that matter is to not loose your volumes. The question of how to backup a docker volume is already answered multiple times on Stack Overflow.

Now be aware that a few docker and docker-compose commands do delete volumes! For instance if you run docker rm -v <my container>, the -v option is to tell docker to also delete associated volumes while deleting the container. Or if you run docker-compose down -v, volumes would also be deleted.


How to backup Wordpress running in a docker-compose project?

Well, the best way is to backup your Wordpress data with a Wordpress plugin that is well known for doing so correctly. It is not because you are running Wordpress in docker containers that Wordpress good practices don't apply anymore.

In the case you need to restore your website, start new containers/volumes with your docker-compose.yml file, go through the minimal Wordpress setup, install your backup plugin and use it to restore your data.

Thomasleveil
  • 69,168
  • 10
  • 106
  • 102