I am writing a Dockerfile for setting up an image for testing a web application. I am basing it on the tutum/lamp image (https://github.com/tutumcloud/tutum-docker-lamp/blob/master/Dockerfile) because that seems to be a good base to start from.
As part of my dockerfile, I want to create a mysql database and set up some stuff in it. However, the tutum/lamp image declares VOLUME ["/etc/mysql", "/var/lib/mysql" ]
, so if I understand correctly, any changes that I make to the MySQL database in the Dockerfile will not be persisted.
- Do I understand that correctly?
If yes,
- Is there a way to "undeclare" those volumes so that those directories will be part of the union file system like everything else?
Thanks!
You can't really undeclare a volume, but you can build your own version of the original image by modifying it's dockerfile.
There has been no change to this problem space in years, so I have created docker-copyedit as a workaround to "undeclare" a volume by editing the metadata of a downloaded image.
Not possible to change an existing container, so you have two options:
Data containers
Create a container that creates a data volume reference:
This can then be used when running the mysql database to persist the data:
The data persists as long as the "dbvol" container exists. It can be deleted at any stage:
Reference: