14

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!

Mikkel
  • 3,284
  • 2
  • 18
  • 20
  • 1
    I'm actually trying to do the exact same thing. I edited the volumes out of tutum/lamp but when I tried to build it I got: `start-apache2.sh: no such file or directory` – pguardiario Oct 13 '14 at 22:20
  • @pguardiario: Did you clone all of the files from the tutum/lamp git directory? You need to get all the supporting files too, not only the Dockerfile. Also, make sure that you run `docker build` in the right directory. – Mikkel Oct 14 '14 at 12:26
  • yes I figured that out too. I got them both to build but I'm still having issues with moving the container. – pguardiario Oct 14 '14 at 23:47

3 Answers3

6

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

King Chung Huang
  • 5,026
  • 28
  • 24
Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
3

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:

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Thank you for the reply. I am aware of the "data container" principle, but I don't know how I would use it in conjunction with the Dockerfile script? I want to create a database and make several additions and changes to it in the script. – Mikkel Oct 11 '14 at 15:01
  • 3
    @Mikkel Then take the dockerfile used by Tutum and run it locally to create your own image. Using local volumes for data is also a lot more efficient from a performance point of view (Aufs is slow). The data container pattern is simply a useful trick to ensure the data volume doesn't get deleted with the container (volumes are only deleted when all container references are gone) – Mark O'Connor Oct 11 '14 at 15:04
  • I was coming to that conclusion myself also (building my own tutum-like image). I was just wondering if there was a way to "undeclare" a volume. If you post your suggestion of building my own image as an answer, I will mark it as the correct answer. – Mikkel Oct 11 '14 at 15:23
0

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.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19