5

I am using docker-compose and I would like to create a relative two-path binding.

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"

This one does result in an error.

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"

This one does work.

I did found this thread: Docker: Mounts denied. The paths ... are not shared from OS X and are not known to Docker

but it didn't help me at all. I did try to add my repository-folder to the file sharing tab of the docker settings but it doesn't allow me to add the folder because it is already inside the group of /Users.

Is the path relative from the docker-compose/docker file?

Anybody got an idea what the problem is? I am really confused.

Thanks in advance

Burg
  • 191
  • 3
  • 15

2 Answers2

4

You can use relative paths, in your case it would be

volumes:
  - "./Bla:/usr/src/html/bla"
  • Thanks a lot. This answer was very helpfull. Didn't know that I have to use . before. – Burg Jan 24 '19 at 07:42
  • @Burg I did not see in docs you should. looks like it's needed to distinguish from volumes. – Alex Martian Dec 03 '19 at 06:40
  • this works with the quotes, i was missing quotes and it does not work without them, but absolute paths work without comments it seems. im using version `3.8` – notsodev Jul 28 '20 at 18:53
1

I think I did found the solution to my own problem.

To do a two-way-binding it looks like you have to use:

$PWD

Inside the hostpath.

In my case:

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

After that it does work. Is this a good solution or does it create any problems which I don't know?

Burg
  • 191
  • 3
  • 15
  • that's ok. $PWD expands to **full** path, not relative. looks to me now relative paths cannot be used... – Alex Martian Dec 03 '19 at 06:36
  • @AlexeiMartianov relative to what directory? Having absolute path to the current directory (that `$pwd` returns) you can then specify path relative to it. – Ilya Serbis Aug 24 '21 at 22:32