Containers are usually immutable and ephemeral.
You do not have to change, you can just re-deploy. (if upgrade/change needs to occur).
What about databases, or unique data?
If you delete container, you will delete data too, so you need to separate data from container binaries.
This problem of separation of data is known as persistent data
Docker gives us two features to ensure these separation of concerns.
1. Volume
- It make special location outside of container UFS(union file system)
- Add
-v <volumeName>:<path>
upondocker container run
to get named volumes
named volumes
:friendly way to assign vols to containers
2. Bind Mounts
- It maps a host file or directory to a container file or directory
- Basically just two locaitons pointing ot the same file(s).
- It skips UFS, and host files overwrite any in container.
- Can't use in Dockerfile, must be at
container run
... run -v /User/bret/stuff:/path/container
(mac/linux)... run -v //c/User/bret/stuff:/path/container
(windows)
$(pwd)
print out current working directory and replace this cmd with that path
docker volume +
prune
cleanup unused volumes
create
create volume byitself. It is required to do this before docker run
to use custom drivers and labels