Reputation: 256
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 ?
Upvotes: 1
Views: 1943
Reputation: 25772
Dockerfile
is for create images not containers.
You can not define a volume
on a image
. The volume
must be defined on execution time when the container is created.
docker run -v /host-folder:/root/containerfolder -i -t imagename
Upvotes: 0
Reputation: 51738
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
Upvotes: 3