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
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).
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 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.
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.
You can use relative paths, in your case it would be
volumes:
- "./Bla:/usr/src/html/bla"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With