Docker Volume

  1. 1.bind mount
  2. 2.volume Instance
  3. 3. tmpfs mount

Volume 可以滿足需要互相交流檔案的需求或者留存資料用途,例如資料共享和資料庫檔案等

如下表,可以有兩種情境

1. Host file         <-- Volume -->  Container file
2. Container-A file  <-- Volume -->  Container-B file

Docker 提供三種掛載類型(mount types):

Mount Type Descript
Bind mount Mount exist host filesystem
Volume Mount volume instance
Tmpfs mount Mount from memory

建議增加Volume,Container必須移除重新生成會比較好

1.bind mount

# -v(--volume) [host-path]:[container-path]

$ docker run -d -p 8080:8080 --name tomcat1 -v ~/docker-data/tomcat/conf:/tomcat/conf tomcat:8

2.volume Instance

$ docker volume create myWar
$ docker run -d -p 8080:8080 --name tomcat1 -v myWar:/tomcat/webapps tomcat:8

3. tmpfs mount

(empty)