Windows 10 bind mounts in docker-compose not working

邮差的信 提交于 2019-12-24 18:23:26

问题


I'm using docker-compose to manage a multi container application. 1 of those containers needs access to the contents of a directory on the host.

This seems simple according to the various sources of documentation on docker and docker-compose but I'm struggling to get it working.

  event_processor:
    environment:
      - COMPOSE_CONVERT_WINDOWS_PATHS=1
    build: ./Docker/event_processor
    ports:
      - "15672:15672"
    entrypoint: python -u /src/event_processor/event_processor.py
    networks:
      - app_network
    volumes:
      - C/path/to/interesting/directory:/interesting_directory"

Running this I get the error message:

ERROR: Named volume "C/path/to/interesting/directory:/interesting_directory:rw" is used in service "event_processor" but no declaration was found in the volumes section.

I understand from the docs that a top level declaration is only necessary if data is to be shared between containers

which isn't the case here.

The docs for docker-compose I linked above have an example which seems to do exactly what I need:

version: "3.2"
services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - type: volume
        source: mydata
        target: /data
        volume:
          nocopy: true
      - type: bind
        source: ./static
        target: /opt/app/static

networks:
  webnet:

volumes:
  mydata:

However when I try, I get errors about the syntax:

ERROR: The Compose file '.\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string

So I tried to play along:

volumes:
  - type: "bind"
    source: "C/path/to/interesting/directory"
    target: "/interesting_directory"

ERROR: The Compose file '.\docker-compose.yaml' is invalid because: services.audio_event_processor.volumes contains an invalid type, it should be a string

So again the same error.

I tried the following too:

volumes:
  - type=bind, source=C/path/to/interesting/directory,destination=/interesting_directory

No error, but attaching to the running container, I see the following two folders;

type=bind, source=C

So it seems that I am able to create a number of volumes with 1 string (though the forward slashes are cutting the string in this case) but I am not mapping it to the host directory.

I've read the docs but I think I'm missing something. Can someone post an example of mounting a a windows directory from a host to a linux container so that the existing contents of the windows dir is available from the container?


回答1:


OK so there were multiple issues here:

1.

I had

version: '3'

at the top of my docker-compose.yml. The long syntax described here wasn't implemented until 3.4 so I stopped receiving the bizarre syntax error when I updated this to:

version: '3.6'

2.

I use my my docker account on 2 windows PCs. Following a hint from another stackoverflow post, I reset Docker to the factory settings. I had to give docker the computer username and password with the notice that this was necessary to access the contents of the local filesystem - at this point I remembered doing this on another PC so I'm not sure whether the credentials were correct on this on. With the correct credentials for the current PC, I was able to bind-mount the volume with the expected results as follows:

   version: '3.6'

   event_processor:
    environment:
      - COMPOSE_CONVERT_WINDOWS_PATHS=1
    build: ./Docker/event_processor
    ports:
      - "15672:15672"
    entrypoint: python -u /src/event_processor/event_processor.py
    networks:
      - app_network
    volumes:
      - type: bind
        source: c:/path/to/interesting/directory
        target: /interesting_directory

Now it works as expected. I'm not sure if it was the factory reset or the updated credentials that fixed it. I'll find out tomorrow when I use another PC and update.



来源:https://stackoverflow.com/questions/50514179/windows-10-bind-mounts-in-docker-compose-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!