Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path binding in docker for volumes in macOS does fail

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

like image 549
Burg Avatar asked Jan 23 '19 08:01

Burg


People also ask

Where are volumes stored Docker Mac?

Unlike bind mount, where you can mount any directory from your host, volumes are stored in a single location (most likely /var/lib/docker/volumes/ on unix systems) and greatly facilitates managing data (backup, restore, and migration).

What is the difference between Docker volume and bind mount?

Though both methods are similar, there is a slight difference. Docker manages Volumes and is usually not affected by other processes running on the same host. In contrast, Bind Mounts are just directories on the host file system and may be modified by other processes other than docker.

How do I mount a directory to a Docker volume?

How to Mount Local Directories using docker run -v. Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to your container. For example, you can start a MySQL database and mount the data directory to store the actual data in your mounted directory.

What is bind volume in Docker?

Bind mounts have been available in Docker since its earliest days for data persisting. Bind mounts will mount a file or directory on to your container from your host machine, which you can then reference via its absolute path. To use bind mounts, the file or directory does not need to exist on your Docker host already.


1 Answers

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

volumes:
  - "./Bla:/usr/src/html/bla"
like image 121
Ondřej Hlaváček Avatar answered Sep 26 '22 04:09

Ondřej Hlaváček