![](/img/trans.png)
[英]Cannot mount local directory into container from docker-compose file
[英]docker-compose mount single file with directory
如果我將文件放在相對於 docker-compose up 命令的子目錄 (myconfig) 中,則無法掛載文件。 $PWD 是 /home/username/temp/ 和 docker-compose 從那里運行。
這不起作用:
version: '3'
services:
proxy:
container_name: proxy
image: nginx
ports:
- "80:80"
volumes:
- $PWD/myconfig/nginx.conf:/etc/nginx/conf.d/default.conf
但是,如果我將 nginx.conf 復制到 $PWD 目錄,則此方法有效:
version: '3'
services:
proxy:
container_name: proxy
image: nginx
ports:
- "80:80"
volumes:
- $PWD/nginx.conf:/etc/nginx/conf.d/default.conf
所以這些都不起作用:
$PWD/myconfig/nginx.conf
./myconfig/nginx.conf
/home/username/temp/myconfig/nginx.conf
但是這些工作,如果我將 $PWD/myconfig/nginx.conf 復制到 $PWD/config.conf:
./nginx.conf
$PWD/nginx.conf
日志:
Creating network "temp_default" with the default driver
Creating proxy ... error
ERROR: for proxy Cannot create container for service proxy: not a directory
ERROR: for proxy Cannot create container for service proxy: not a directory
ERROR: Encountered errors while bringing up the project.
但是,當我使用長語法時,它正在使用子目錄:
version: '3'
services:
proxy:
container_name: proxy
image: nginx
ports:
- "80:80"
volumes:
- type: bind
source: $PWD/myconfig/nginx.conf
target: /etc/nginx/conf.d/default.conf
這是我想念的東西,還是這是一個錯誤或缺乏文檔?
Docker 和 docker-compose 版本:
➜ ~ docker version
Client: Docker Engine - Community
Cloud integration: 1.0.7
Version: 20.10.2
API version: 1.41
Go version: go1.13.15
Git commit: 2291f61
Built: Mon Dec 28 16:17:34 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.2
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8891c58
Built: Mon Dec 28 16:15:28 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
➜ ~ docker-compose version
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
你的例子對我來說很好。
# docker-compose --version
docker-compose version 1.25.0, build unknown
由於您提到即使使用顯式路徑它也不起作用,而它在您的主文件夾中工作時,我建議檢查myconfig
文件夾的權限。 確保所有用戶都被允許訪問和讀取('x' 和 'r')
# ls -ltr
total 8
drwxr-xr-x 2 root root 4096 Feb 23 06:03 myconfig
-rw-r--r-- 1 root root 182 Feb 23 06:05 docker-compose.yml
如果權限不正確,請使用chmod a+xr myconfig/
和chmod a+r myconfig/nginx.conf
設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.