In my docker compose file, I specify two services: phpant (a custom image derived from debian with PHP compiled and postfix running so PHP can actually send emails) and a mysqldb service that pulls the latest from the docker hub.
In the phpant service, I define a volume:
volumes:
- "/var/www/html/config/"
After installation, we write config files to this folder. We are using a volume because we want the config data to persist even if we roll out a new / updated image.
However, when we push a new image, it's losing the config files, and this directory ends up empty.
What did I do wrong? How do I get the data volume to persist even after I update the docker image for that service?
Note: The Wordpress image appears to do this correctly, which is where I got the idea in the first place. I tried to emulate what they did, but clearly, I have skipped / missed a step.
You specified only a path within the container for your volume. In this configuration, Docker creates a new volume each time the container is recreated.
If you want the volume data to be persistent, you need to specify a path accessible to the container host where the volume data can be stored. For example, relative to your
docker-compose.yml
:See the documentation for more ways to configure volumes.