My cenario for the problem
I have a cenario where I use the officcial postgresql and percona database image. For the developers I distribute the docker image with DB data included. So when the users spin up the docker image DB data are mapped to the local dir like this in the docker compose file.
volumes: - "mysqldata:/var/lib/mysql"
When the developers want to reset the DB they just run docker-compose down and docker volume prune. Then just run the docker-compose up -d and everything is reset.
My problem is when I create the DB image. I do this using a CI server. I have to copy the setup files from percona and postgres and run a build locally. I am not able to use allready built images from docker hub as they have this line in the dockerfile:
VOLUME ["/var/lib/mysql", "/var/log/mysql"]
If I restore a minimized db to this image the data will not be stored in the final docker image. So I need to build a new image and exlude the data dir in the docker file.
Is there anyway for me to use a official db image, and in my ci server add DB data to the image without doing the docker build my self? When I do my own build it is hard to keep verions because they are removed from the source at percona and postgres.
I would hope it would be possible to use a parameter when you spin up docker images preventing defined volumes from the docker file to be mounted.
Example docker run .... --local-volume-mount
This way I could mount the image, restore the db and push to registry with DB date on the image and when I run the image in my docker compose the db data will be copied out from the docker image as normal.