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. $PWD is /home/username/temp/ and docker-compose up run from there.

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:

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:

./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 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

1 answer

  • answered 2021-02-23 06:11 jordanvrtanoski

    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. Make sure all users are allowed access and read ('x' and '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