Search code examples
dockerdockerfilemount

Dockerfile - How to define mounting of host file system to the container


I want to mount a folder of the host system to the container and it need to be defined in the Dockerfile so that user doesn't need to do it manually by passing the argument in the command line to run the container. How to achieve this ?


Solution

  • This simply cannot be done. Docker images are designed to be portable. Host mounts are host specific. Thus if you are able to specify a host mount at build time, it will make the image non-portable across machine that don't have this mount folder. Thus this is why this option is not available.

    You can use docker compose to help the user not choose the mount folder. Take a look at How do I mount a host directory as a volume in docker compose