简体   繁体   中英

Docker volume located in /tmp on OSX empty

When I try to run a container on OSX (with docker-machine on a Parallels VM) and mount a volume located in /tmp the volume seems empty.

> mkdir -p /tmp/foo/bar
> docker run -ti -v /tmp/foo:/foo ubuntu ls /foo

I expect to see it list bar , however, it's empty. This works:

> mkdir -p /Users/myuser/tmp/foo/bar
> docker run -ti -v /Users/myuser/tmp/foo:/foo ubuntu ls /foo
bar

The same happens with folders created with mktemp which end up in /folders . How can I make docker mount those folders correctly?

This is a well known problem. The reason behind this is linked to the VM, when it's created it mounts the folders within your Users directory, which makes it the only folder available to the containers. Here is the similar issue https://github.com/docker/kitematic/issues/1192

As a workaround, you can simply add the desired location(s) to the underlying VirtualBox machine. If your docker machine is default and you would like to be able to mount external volumes, you can use:

VBoxManager sharedfolder add default --name Volumes --hostpath /Volumes --automount

Afterwards, docker run -v /Volumes/Data:/mnt/Data ls /mnt/Data will work.

It's 2022 and I found myself in the same situation. Additional information that may be useful is: /tmp -> /private/tmp is a symlink (OSX) that may be causing a problem. In docker run command in volumes I replaced /tmp with /private/tmp and it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM