Bootstrap FreeKB - Docker - Mount a file or directory in a container using the docker run -m or --mount command
Docker - Mount a file or directory in a container using the docker run -m or --mount command

Updated:   |  Docker articles

The --mount or --volume option can be used to:

  • mount a file or directory on your Docker system to a file or directory in the container
  • mount an NFS share in the container

You can use:

For example, let's can use the --mount or --volume option to mount /usr/local/main.py on the Docker host system to /app/main.py in a Docker container.

 

For example, here is how you could mount /usr/local/main.py on the Docker system to /app/main.py in the container.

sudo docker run \
--mount \
src=/usr/local/main.py,\
dst=/app/main.py,\
type=bind \
foo:latest

 

As an example, let's say you have a container named foo, and you want to mount an NFS share in the container. In this example, the the docker run command is used to start/create the container using the foo:latest image.

sudo docker run \
--mount \
src=mynfsshare,\
dst=/mnt,\
type=volume,\
volume-driver=local,\
volume-opt=type=nfs,\
volume-opt=device=:/,\
\"volume-opt=o=addr=10.11.12.13,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport\"\
foo:latest

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f2ddf4 in the box below so that we can be sure you are a human.