简体   繁体   English

docker-compose 挂载单个文件带目录

[英]docker-compose mount single file with directory

I can't mount a file if I put it in a subdirectory (myconfig) relative to the docker-compose up command.如果我将文件放在相对于 docker-compose up 命令的子目录 (myconfig) 中,则无法挂载文件。 $PWD is /home/username/temp/ and docker-compose up run from there. $PWD 是 /home/username/temp/ 和 docker-compose 从那里运行。

This is not working:这不起作用:

version: '3'
services: 
  proxy:
    container_name: proxy
    image: nginx
    ports:
      - "80:80"
    volumes:
      - $PWD/myconfig/nginx.conf:/etc/nginx/conf.d/default.conf

But this works if I copy nginx.conf to the $PWD directory:但是,如果我将 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

So none of these works:所以这些都不起作用:

$PWD/myconfig/nginx.conf
./myconfig/nginx.conf
/home/username/temp/myconfig/nginx.conf

But these work, if I copy $PWD/myconfig/nginx.conf to $PWD/config.conf:但是这些工作,如果我将 $PWD/myconfig/nginx.conf 复制到 $PWD/config.conf:

./nginx.conf 
$PWD/nginx.conf

log:日志:

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.

However when I use the long syntax, it is working with subdirectory:但是,当我使用长语法时,它正在使用子目录:

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

Is here something that I miss, or is this a bug or lack of documentation?这是我想念的东西,还是这是一个错误或缺乏文档?

Docker and docker-compose version: 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

Your example works fine for me.你的例子对我来说很好。

# docker-compose --version
docker-compose version 1.25.0, build unknown

Since you mentioned that even with explicit path it was not working, while it was working inside your main folder, I would suggest to check the permissions for the myconfig folder.由于您提到即使使用显式路径它也不起作用,而它在您的主文件夹中工作时,我建议检查myconfig文件夹的权限。 Make sure all users are allowed access and read ('x' and 'r')确保所有用户都被允许访问和读取('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

if the the permissions are not correct, set them with chmod a+xr myconfig/ and chmod a+r myconfig/nginx.conf如果权限不正确,请使用chmod a+xr myconfig/chmod a+r myconfig/nginx.conf设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 docker-compose 文件将本地目录挂载到容器中 - Cannot mount local directory into container from docker-compose file 使用docker-compose绑定单个文件 - Bind-Mount a single File with docker-compose 使用docker-compose从卷挂载单个文件 - Mount single file from volume using docker-compose 如何在 docker-compose 中挂载单个文件 - How do I mount a single file in docker-compose 无法使用docker-compose挂载文件 - Unable to mount a file with docker-compose 如何使用 docker-compose 将 Docker 目录挂载到主机目录中 - How to mount Docker directory into host directory with docker-compose docker 无法使用 docker-compose 将主机目录安装到 docker 容器 - docker unable to mount host directory to docker container with docker-compose 如何使用docker-compose挂载主机目录,运行主机时指定“~/path/on/host”,不在docker-compose文件中 - How to mount a host directory with docker-compose, with the "~/path/on/host" to be specified when running the host, not in the docker-compose file docker工具箱-无法使用docker-compose挂载目录 - docker toolbox - can't mount directory using docker-compose Jenkins 中的 Docker-compose 错误“docker-compose:没有这样的文件或目录” - Docker-compose error in Jenkins "docker-compose: No such file or directory"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM