Search code examples
dockerdocker-volume

Is it possible to mount the host path or docker volume to the path in the image from dockerfile?


I want to mount my host path (or docker volume) to the path in the image from dockerfile.

Dockerfile can copy the host data or directory to the data or directory in the image.

But I want to bind or mount not copy!

It is similar to "docker run -v" option but I wonder that it is done by creating the image from dockerfile.

Is any solution for this issue?


Solution

  • No, as far as I am aware, a host path cannot be mounted via the Dockerfile due to the portability of docker images and the different host architectures/directory layouts etc. See dockerfile volumes note 4.

    Using VOLUME within the dockerfile will create a docker volume on the host at run-time of the container, but it cannot be specified to be a host directory. This answer explains the use of dockerfile VOLUME quite well. To use a host directory, you will need to do it at run time.