docker 中的相对路径绑定在 macOS 中确实失败

Relative path binding in docker for volumes in macOS does fail

我正在使用 docker-compose,我想创建一个相对的双路径绑定。

Folder structure and path at the host machine:
/Users/username/Documents/Repos/docker-gulp-template/bla
docker-gulp-template
  Dockerfile
  docker-compose.yml
  Bla (Folder)

Path structure inside the container:

/usr/src/html/bla

version: '3'
services:
  bla:
    command: /bin/bash    
    stdin_open: true
    #tty: true
    container_name: docker-gulp-template
    #restart: always
    build: .
    ports:
      - '80:3000'
    volumes:
      - "/bla:/usr/src/html/bla"

这个确实会导致错误。

ERROR: for docker-gulp-template  Cannot start service bla: b'Mounts denied: \r\nThe path /bla\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'
    volumes:
      - ".:/usr/src/html/bla"

这个确实有效。

我确实找到了这个线程:

但这对我一点帮助都没有。 我确实尝试将我的存储库文件夹添加到 docker 设置的文件共享选项卡,但它不允许我添加该文件夹,因为它已经在 /Users 组中。

路径是 docker-compose/docker 文件的相对路径吗?

有人知道问题出在哪里吗?我真的很困惑。

提前致谢

我想我确实找到了解决我自己问题的方法。

要进行双向绑定,您似乎必须使用:

$PWD

在主机路径内。

就我而言:

  volumes:
      - "$PWD/bla:/usr/src/html/bla"

在那之后它确实起作用了。这是一个好的解决方案还是会产生我不知道的任何问题?

您可以使用相对路径,在您的情况下是

volumes:
  - "./Bla:/usr/src/html/bla"