How to “undeclare” volumes in docker image?

2019-01-25 10:35发布

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!

标签: mysql docker
3条回答
仙女界的扛把子
2楼-- · 2019-01-25 11:12

You can't really undeclare a volume, but you can build your own version of the original image by modifying it's dockerfile.

查看更多
看我几分像从前
3楼-- · 2019-01-25 11:21

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.

查看更多
Luminary・发光体
4楼-- · 2019-01-25 11:25

Not possible to change an existing container, so you have two options:

  1. Take the Tutum container and build your own variant
  2. Manage persistence of the tutum container using a data container.

Data containers

Create a container that creates a data volume reference:

docker run -it --name dbvol -v /var/lib/mysql ubuntu env

This can then be used when running the mysql database to persist the data:

docker run -d --volumes-from dbvol -p 3306:3306 tutum/mysql:5.6

The data persists as long as the "dbvol" container exists. It can be deleted at any stage:

docker rm dbvol

Reference:

查看更多
登录 后发表回答