Container Lifetime & Persistent Data

skang6283·2021년 1월 24일
0

Docker

목록 보기
5/6

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> upon docker 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)

Commands & Tips

$(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

  • When making a new volume of for a container, you should check Docker Hub to see where the data path should be.
profile
Hi :) I'm Max

0개의 댓글