My Docker notebook
REF: https://docs.docker.com/storage/bind-mounts/
If you use -v
or --volume
to bind-mount a file or directory that does not yet exist on the Docker host, -v
creates the endpoint for you. It is always created as a directory.
If you use --mount
to bind-mount a file or directory that does not yet exist on the Docker host, Docker does not
automatically create it for you, but generates an error.
# Option 1: using --mount
docker run -d -it --name devtest --mount type=bind,source="$(pwd)"/target,target=/app nginx:latest
# Option 2: using -v
docker run -d -it --name devtest -v "$(pwd)"/target:/app nginx:latest
# Both options above have the same result
docker inspect devtest
# Output
...
"Mounts": [
{
"Type": "bind",
"Source": "/tmp/source/target",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
# Option 1: using --mount
docker run -d -it --name broken-container --mount type=bind,source=/tmp,target=/usr nginx:latest
# Option 2: using -v
docker run -d -it --name broken-container -v /tmp:/usr nginx:latest
# Both options have the same result:
docker: Error response from daemon: oci runtime error: container_linux.go:262:
starting container process caused "exec: \"nginx\": executable file not found in $PATH".
# The container is created but does not start. Remove it.
docker container rm broken-container
# Option 1: using --mount
docker run -d -it --name devtest --mount type=bind,source="$(pwd)"/target,target=/app,readonly nginx:latest
# Option 2: using -v
docker run -d -it --name devtest -v "$(pwd)"/target:/app:ro nginx:latest
# Both options above have the same result
docker inspect devtest
# Output
...
"Mounts": [
{
"Type": "bind",
"Source": "/tmp/source/target",
"Destination": "/app",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
}
],
rprivate
for both bind mounts and volumes./mnt
, which is also mounted on /tmp
. The
propagation settings control whether a mount on /tmp/a
would also be available on /mnt/a
. Each propagation
setting has a recursive counterpoint. In the case of recursion, consider that /tmp/a
is also mounted as /foo
.
The propagation settings control whether /mnt/a
and/or /tmp/a
would exist.Propagation setting | Description |
---|---|
shared |
Sub-mounts of the original mount are exposed to replica mounts, and sub-mounts of replica mounts are also propagated to the original mount. |
slave |
Similar to a shared mount, but only in one direction. If the original mount exposes a sub-mount, the replica mount can see it. However, if the replica mount exposes a sub-mount, the original mount cannot see it. |
private |
The mount is private. Sub-mounts within it are not exposed to replica mounts, and sub-mounts of replica mounts are not exposed to the original mount. |
rshared |
The same as shared, but the propagation also extends to and from mount points nested within any of the original or replica mount points. |
rslave |
The same as slave, but the propagation also extends to and from mount points nested within any of the original or replica mount points. |
rprivate |
The default. The same as private, meaning that no mount points anywhere within the original or replica mount points propagate in either direction. |
To view the approximate size of a running container, you can use the docker ps -s command. Two different columns relate to size.
REF: https://docs.docker.com/storage/storagedriver/#container-size-on-disk
REF: https://docs.docker.com/storage/storagedriver/select-storage-driver/
devicemapper
storage driver must use direct-lvm
mode.loopback
devices, uses system
resources more efficiently, and block devices can grow as needed. However, more set-up is required than loop-lvm
mode.