percona icon indicating copy to clipboard operation
percona copied to clipboard

Create a docker image with no volume mounts

Open eriksenonline opened this issue 8 years ago • 3 comments

In the dockerfile for percona there is a volume mount for persistence
VOLUME ["/var/lib/mysql", "/var/log/mysql"]

This is very good for production! But for development, I wish there was a way to NOT mount these volumes. Let me explain.

On my CI server, I create a development database image that contains MySQL data inside the container. I achieve this by forking the percona docker file and build percona my self without the volume mounts.

So when I restore my development database data to this image and push the image version to my docker hub, the data stay on the image.

In my docker compose file I map the /var/lib/mysql to local for persistence.

What I would like is this

Can you make a version of the percona image that does not mount the volumes in the Dockerfile? Let us mount the volumes when we want to? This way I can build and add DB data to the image for distribution. And then I do not have to maintain my own set of images that is more or less exactly the same as yours.

I have tried to get docker to make a docker build --no-volumes parameter or similar, but no one understands why it is needed. I guess I am very bad to explain.

eriksenonline avatar Feb 28 '18 10:02 eriksenonline

I also had this usecase and resorted to creating a child image that uses a different datadir:

FROM percona:5.7.20

# Changes datadir to a non-volume so that it is persisted
RUN sed -i 's:/var/lib/mysql:/var/lib/mysqldata:' /etc/mysql/percona-server.conf.d/mysqld.cnf

Strangely, this stops working with Percona 5.7.21+.

Also while on this subject, Volumes and dockerfiles don't mix.

uuf6429 avatar May 09 '18 10:05 uuf6429

I've had success with the following:

FROM percona:5.7
CMD ["--datadir=/datadir"]

tianon avatar May 09 '18 19:05 tianon

Issue seems resolved so going to close

wglambert avatar Sep 07 '18 19:09 wglambert