Search code examples
mysqldockervolumedockerfile

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?


Solution

  • 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.