docker 掛 volumes

-v volumes
#使用 -v 如本地目錄不存在,docker 會自動建立目錄

docker run -itd -P –name web -v /webapp training/webapp python app.py
#建立 volume /webapp 掛載至 training/webapp , /webapp 位在 /var/lib/docker/volumes
可以用 "docker volume ls" 命令觀察 volumes 建立位置

docker run -itd -P –name web -v /docker/webapp:/opt/webapp:ro training/webapp python app.py
#將 Host /src/webapp 掛到 /opt/webapp (目錄須是絕對路徑), 來源若沒有會自動建立
#ro 唯獨

docker run –rm -it -v ~/.bash_history:/.bash_history ubuntu /bin/bash
# 檔案掛載 ,編輯會造成 inode 改變 ,建議掛載檔案的目錄
root@2affd44b4667:/# history
1 ls
2 diskutil list
#這樣可以記錄在容器輸入的命令

#下面是用另一種方式掛載 –mount
$ docker run -d -P \
–name web \
# -v /src/webapp:/usr/share/nginx/html \
–mount type=bind,source=/src/webapp,target=/usr/share/nginx/html \
nginx:alpine

#以唯讀readonly方式,默認是讀寫
–mount type=bind,source=/src/webapp,target=/usr/share/nginx/html,readonly \
# –mount 如果本地目錄不存在,Docker 會報錯。

# 以下是 掛載 .bash_history,紀錄命令 history
–mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history \
ubuntu:18.04 \
bash

本篇發表於 docker。將永久鍊結加入書籤。

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>