[英]docker-compose volumes syntax for local driver to mount a file
我正在嘗試在我的docker-compose.yml
的volumes
部分安裝一個文件(nginx.conf)。 我可以毫無問題地將目錄掛載為卷,但是,我不清楚文件的語法是什么。
我在我的volumes
部分定義了以下內容
volumes:
roundcubeweb:
driver: local
driver_opts:
type: none
o: bind
device: /mnt/docker/volumes/roundcube/html
nginxconf:
driver: local
driver_opts:
type: none
o: bind
device: /mnt/docker/volumes/roundcube/nginx.conf
稍后,我的服務部分下有以下內容
nginx:
image: nginx:latest
deploy:
replicas: 1
restart: always
depends_on:
- roundcube
ports:
- "8082:80"
volumes:
- roundcubeweb:/var/www/html
- nginxconf:/etc/nginx/conf.d/default.conf
當我嘗試啟動它時,我收到以下錯誤:
錯誤:對於roundcube_nginx_1無法為服務nginx創建容器:無法掛載本地卷:掛載/mnt/docker /volumes/roundcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,標志:0x1000:不是目錄
錯誤:對於 nginx 無法為服務 nginx 創建容器:無法掛載本地卷:掛載 /mnt/docker/volumes/rou ndcube/nginx.conf:/var/lib/docker/volumes/roundcube_nginxconf/_data,標志:0x10000000目錄錯誤:啟動項目時遇到錯誤。
我發現如果我在 nginx 服務部分的卷聲明中內聯文件位置,那么它就可以正常工作。 例如:
volumes:
- roundcubeweb:/var/www/html
- /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
不能在volumes
部分掛載文件嗎? 本地驅動的參數有參考嗎?
我認為不可能讓獨立的 Docker 卷指向特定文件而不是目錄。 它可能與有關如何管理和安裝卷的 Docker 設計有關(試圖找到文檔或相關代碼,但找不到任何內容)
local
驅動程序的參數似乎采用與 Linux mount
命令類似的參數。 Docker 卷文檔中似乎暗示了這一點,盡管不是很清楚:
本地驅動程序接受掛載選項作為 o 參數中的逗號分隔列表
我發現如果我在 nginx 服務部分的卷聲明中內聯文件位置,那么它就可以正常工作。 例如:
volumes: - roundcubeweb:/var/www/html - /mnt/docker/volumes/roundcube/nginx.conf:/etc/nginx/conf.d/default.conf
在您的示例中,您正在執行Bind Mound而不是使用Volumes ,Docker 的處理方式不同,更適合您在容器中安裝本地文件的用例。 我認為在您的情況下使用 Bind Mount 是合適的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.