Tools, FAQ, Tutorials:
Docker Data Storage - Bind Mounts
How to create a new Bind mount to a Docker container?
✍: FYIcenter.com
Bind mounts may be stored anywhere on the host system. They may even be
important system files or directories. Non-Docker processes on the Docker host
or a Docker container can modify them at any time.
You have two options "--volume" and "--mount" on the "docker container create/run" command to create bind mounts.
"--volume ...:..." Option - Allows you to create a new bind mount to the new Docker container with default configuration.
"--mount type=bind,..." Option - Allows you to create a new bind mount to the new Docker container with specific configurations.
For example, the following command "docker run --volume" runs a new container with host's /tmp mounted to docker's /tmp.
fyicenter# docker run --volume /tmp:/tmp -tid --name fyi_test alpine fyicenter# docker exec -ti fyi_test /bin/sh / # df -h Filesystem Size Used Available Use% Mounted on overlay 50.0G 22.3G 27.7G 45% / tmpfs 64.0M 0 64.0M 0% /dev tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup shm 64.0M 0 64.0M 0% /dev/shm /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /tmp /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/resolv.conf /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/hostname /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /etc/hosts ... / # ls -l /tmp drwxr-xr-x 2 1000 1000 20 hsperfdata_fyicenter drwx------ 2 1000 1000 27 ssh-BSGkGtPZOO / # exit fyicenter# docker container stop fyi_test fyi_test fyicenter# docker container rm fyi_test fyi_test
If you want to create a new bind mount as read only, you need to use the "docker run --mount type=bind,readonly,..." option as shown below.
fyicenter# docker run --mount type=bind,readonly,source=/tmp,destination=/tmp \ -tid --name fyi_test alpine fyicenter# docker exec -it fyi_test /bin/sh / # df -h Filesystem Size Used Available Use% Mounted on overlay 50.0G 22.3G 27.7G 45% / tmpfs 64.0M 0 64.0M 0% /dev tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup shm 64.0M 0 64.0M 0% /dev/shm /dev/mapper/cl-root 50.0G 22.3G 27.7G 45% /tmp ... / # exit fyicenter# docker container stop fyi_test fyi_test fyicenter# docker container rm fyi_test fyi_test
⇒ Docker Data Storage - Multiple Mounts
⇐ Docker Data Storage - Volume Mounts
2021-08-15, ∼995🔥, 0💬
Popular Posts:
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
What is EPUB 3.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 3.0 Metadata "dc:publisher" ...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...