Containers are immutable and ephemeral
This is an issue if our application generates persistent data
Docker has two solutions to deal with this problem:
- Volume: Make special volume outside of UFS
- Bind Mount: Maps host directory to container directory
Bind Mount
Bind Mounts cannot be specified in Dockerfile
they have to be created at runtime
If there is a file that is present on both host and container when we use bind mounts the host file will always win (The files in the container are not deleted they are just not present when bind mount is used)
On PowerShell for command substitution use ${pwd}
Volume
Volumes are not deleted when an container is destroyed
Volume can be created beforehand using the docker volume create
command this is generally used when we need to specify a driver for the volume
At the end of the path we can added :ro
to make the path/volume read only
\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes
When using Docker Desktop with WSL the data on the volumes can be found at:
Copy Command
The copy command can be used to modify files in present in container volume