Unlike volume, it mounts files and directories managed by the host user on a container. Again, the same file or directory can be mounted in multiple containers. Since it is an area managed by the user, basically, prepare the files and directories of the mount source in advance, specify the path, and mount it in the container. By placing the project source code and configuration file on the host and mounting it, you can check the operation while editing the file on the host side.
-# "$(pwd)"Source directory on the current directory(not exist)Is mounted.
$ docker run -itd --name bind-test1 -v “$(pwd)”/source:/app nginx
$ ls
source
If you use -v, a directory is automatically created on the host if the directory does not exist.
-# “$(pwd)”/You are mounting a directory that does not exist in source2.
$ docker run -itd —-name bind-test2 —mount type=bind,source=“$(pwd)”/source2,target=/app nginx
Specify Type as bind. Execute in the state where the directory called source2 does not exist in the current directory. In this case an error will occur. In case of --mount, an error will occur if the source directory does not exist. This will prevent you from accidentally mounting an empty directory. The status of bind mount can be confirmed by displaying the detailed information of the container as well as volume.
-# bind-Detailed confirmation of test1
$ docker inspect bind-test1
"Mounts": [
{
"Type": "bind",
"Source": "/home/docker/source",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
You can check each by Type, Source, and Destination. It is mounted readable and writable by default. Note that bind mount hides the mount directory and files in the bind directory. If you cover important files and directories with bind, the container may not work properly. You can also mount it read-only with bind mount.
Mount the host memory area on the container as a file system. Since the data is stored in the memory, the data will be lost if the docker host is shut down or the container is stopped. The purpose is to use it as a place to store data that is temporarily stored instead of storing persistent data, and store data that can be deleted without any problem. Cache, one-time password, etc. You can optionally limit the mount size.
-#Example
$ docker run -itd --name tmptest --mount type=tmpfs,destination=/app nginx
When using tmpfs, specify tmpfs for type. By default, the mount size is unlimited and if you run out of memory, swap will be used. The mount size can be limited by specifying options.
-#Example
$ docker run -itd --name tmptest2 --mount type=tmpfs,destination=/app,tmpfs-size=500000000,tmpfs-mode=700 nginx
I set the mount size to 500MB and the file mode to 700.
Recommended Posts