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.
If yes,
Thanks!
In Dockerfile you can specify only the destination of a volume inside a container. e.g. /usr/src/app . When you run a container, e.g. docker run --volume=/opt:/usr/src/app my_image , you may but do not have to specify its mounting point ( /opt ) on the host machine.
Remove one or more specific volumes - Docker 1.9 and laterUse the docker volume ls command to locate the volume name or names you wish to delete. Then you can remove one or more volumes with the docker volume rm command: List: docker volume ls.
Adding a Volume To a Running Docker Container Containers must have their volumes configured on startup, which means to add a new volume, you must restart the container. While there is a hacky solution (more on that below), it's highly recommended that a container restart should be done anyway.
You can manage volumes using Docker CLI commands or the Docker API. Volumes work on both Linux and Windows containers. Volumes can be more safely shared among multiple containers. Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
You can't really undeclare a volume, but you can build your own version of the original image by modifying its dockerfile.
Not possible to change an existing container, so you have two options:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With