Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - Multiple duplicate volume declarations; what happens?

I'm trying to set up a persistent data volume for my MySQL docker container.

I'm using the official MySQL image which has this in the Dockerfile:

VOLUME /var/lib/mysql

If I invoke

-v /var/lib/mysql:/var/lib/mysql

during runtime, does my command take precedence, or do I have to remove the VOLUME declaration from the Dockerfile?

like image 369
Chockomonkey Avatar asked Aug 27 '15 17:08

Chockomonkey


1 Answers

Take a look at https://docs.docker.com/reference/builder/#volume - the VOLUME command is declaring a mount point so it can be used by other hosts with the --volumes-from as well the VOLUME command tells docker that the contents of this directory is external to the image. While the -v /dir1/:/dir2/ will mount dir1 from the host into the running container at dir2 location.

In other words, you can use both together and docker will mount the -v properly.

like image 70
Michael Avatar answered Oct 16 '22 12:10

Michael