1 minute read

Tags: ,

Udemy




Section 5 Overview

  • Defining the problem of persistent data
  • Data Volumes
  • Data Mounts

Container Lifetime & Persistent Data

  • Containers are usually immutable and ephemeral
  • Immutable infrastructure: only re-deploy containers, never change
  • This is the ideal scenario, but what about databases, or unique data?
  • Docker gives us features to ensure these separation of concerns
  • This is known as persistent data
  • Two ways: Volumes and Bind Mounts
  • Volumes: make special location outsides of container UFS (union file system)
  • Bind Mounts: link container path to host path

Container Lifetime & Persistent Data

Docker 工作現場 實戰寶典 pg. 142

Imgur

docker create volume create datavol

docker volume ls
  • ex:
docker container run -it --rm -v datavol:/data alpine
echo "This is a named volume demo" > /data/demo.txt
  • 離開 alpine
docker container run --rm -v datavol:/data ubuntu cat /data/demo.txt
  • inspect
docker volume inspect datavol
  • 用 tree 看 (linux)
sudo tree -a /var/lib/docker/volumes/datavol
  • 生活好涼拌

    • docker volume create -help
    • docker volume ls -help
    • docker volume inspect -help

Persisten Data Bind Mounting

mkdir $HOME/data_share
echo "data sharing demo" > $HOME/data_share/demo.txt
docker container run --rm -v $(HOME)/data_share:/data ubuntu cat /data/demo.txt

udemy-docker-mastery/dockerfile-sample-2

作業 Named Volumes and Bind Mounts