I distribute docker images with DB data for development, but the build process is not so smooth

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.

  - "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

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.

My solution

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.

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.

Any idea?

I had a similar problem but I’ve followed instructions in the official mysql image (see https://hub.docker.com/_/mysql/)

  1. have a running container with the image and the right version of MySQL (say 5.5) that works as a server

docker run --name mycontainerSQL -e MYSQL_ROOT_PASSWORD=mypassword -d mysql:5.5

  1. fill the server with some data (i.e. a dump from the working db) using the same image as client

docker run -i mysql:5.5 mysql -h172.17.0.2 -DMETEO -u root -p mypassword < METEO_creation.sq

  1. work with the database for development you need then stop the server!