Docker shared folders on a Mac :(

I’m using the docker builder on packer and having an issue. I’m posting here (as well as the packer forums) because it looks to be more of a docker issue than a packer issue.

When I run the packer docker builder, packer is running the following docker command:

docker run -v /var/folders/j4/nqyjdv994637sq_l7_d9465h0000gn/T/packer-docker426021951:/packer-files -d -i -t ubuntu /bin/bash

Docker then fails with the following error:

Build ‘docker’ errored: Error running container: Docker exited with a non-zero exit status.
Stderr: docker: Error response from daemon: Mounts denied: -for-mac/osxfs/#namespaces for more info.
.
sq_l7_d9465h0000gn/T/packer-docker426021951
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker → Preferences… → File Sharing.
See https://docs.docker.com/docker.

I have Mac OS version 10.11.5, docker version ‘1.12.5, build 7392c3b’ and packer version 0.12.1. I have shared the /var/folders directory in docker (which it translates to /private). After hours of googling it seems I am the only person in the universe having this issue. For what its worth, the packer config is the most simple possible, simply:

{
  "builders": [
    {
      "type": "docker",
      "image": "ubuntu",
      "export_path": "image.tar"
    }
  ]
}

I’m using docker for other things (chef and test kitchen and the test kitchen docker driver) and they work fine.

The issue looks to be your path to your mac folder is being truncated at the first space spaces need to be marked with a \ for example a directory called /January 2017 on your mac would be referenced in the command as /January\ 2017/

hope this helps

Sorry, where’s the space?

Hmmm should have zoomed in they are under scores…LOL sorry,

I do see one thing is /packer-files the directory on your mac?

The reason I ask is the error is due to not finding sq_l7_d9465h0000gn/T/packer-docker426021951 on the host you are deploying the container to…

the syntax is /HOST-DIR:/CONTAINER-DIR

if this model is being followed correctly then you need to look at whether docker preferences > filesharing has access to the folder you want to map in the container.

Yes, file sharing has access to /private. I added /var/folders to sharing but it changed it to /private.

Under /private is the path displayed like /private/var/log/ ?

If not there is something wrong with mapping the path you provided docker…
maybe a permission issue…?

I am guessing at this point… I had no problem adding a directory and mapping that path.

Here’s what I got:

doug@ip-10-0-0-44 slice-motd (dev) (master)*$ ls -l /private
total 0
drwxr-xr-x  95 root  wheel  3230 Dec 21 23:12 etc
drwxr-xr-x   2 root  wheel    68 Aug  1  2015 tftpboot
drwxrwxrwt  39 root  wheel  1326 Jan 10 08:02 tmp
drwxr-xr-x  24 root  wheel   816 Jun 27  2016 var

doug@ip-10-0-0-44 slice-motd (dev) (master)*$ ls -l /private/var
total 0
drwx------    2 root       wheel         68 Mar 13  2016 agentx
drwxr-xr-x    8 daemon     wheel        272 May  4  2016 at
drwx------  611 root       wheel      20774 Jan  4 15:22 audit
drwx------    2 root       wheel         68 Feb 25  2016 backups
drwxr-xr-x   68 root       wheel       2312 Jan  9 21:03 db
drwxr-xr-x    2 root       sys           68 Feb 25  2016 empty
drwxrwxrwx    5 root       wheel        170 Aug  9 11:26 folders
drwxr-x---    2 _jabber    _jabber       68 Aug  1  2015 jabberd
drwxr-xr-x    3 root       wheel        102 Aug  1  2015 lib
drwxr-xr-x   79 root       wheel       2686 Jan 10 07:20 log
drwxrwxr-x    2 root       mail          68 Feb 25  2016 mail
drwxr-xr-x    3 root       wheel        102 Feb 25  2016 msgs
drwxr-xr-x    2 root       wheel         68 Feb 25  2016 netboot
drwxr-xr-x    5 _networkd  _networkd    170 Jun 27  2016 networkd
drwxr-x---    8 root       wheel        272 Dec 13 11:39 root
drwxr-xr-x    4 root       wheel        136 Jun 27  2016 rpc
drwxrwxr-x   33 root       daemon      1122 Jan 10 07:43 run
drwxr-xr-x    2 daemon     wheel         68 Feb 25  2016 rwho
drwxr-xr-x    7 root       wheel        238 May  4  2016 spool
drwxrwxrwt   15 root       wheel        510 Jan 10 08:38 tmp
drwxr-xr-x    3 root       wheel        102 Jan  9 13:22 vm
drwxr-xr-x    4 root       wheel        136 Jun 27  2016 yp

doug@ip-10-0-0-44 slice-motd (dev) (master)*$ ls -ld /private/var/log
drwxr-xr-x  79 root  wheel  2686 Jan 10 07:20 /private/var/log

Someone who understands how the Docker App works might need to jump in.
if you run PS -Ajcf | grep docker you will see docker is running under your UID I am not seeing your issues but I have my Mac user ID as part of the Wheel group which is why I have no issues i think

this is not an MacOS default for a user so you may need to change that to resolve the issues with access to VAR…

This is a guess on my part so you may want to get another opinion. But I have verified my user is part of group wheel so I have the permissions I need and so does the docker process running under my ID.

I see you have given others RWX did you do this recursively? chmod -R?

The only other thing I see is the docker command is missing some variables usually needed but this should be spinning a different error…

this is how a docker command should look

docker run -it --name ‘containername’ -v /host folder:container folder -p ‘port number to advertise’:‘port number inside container’ -d ‘image name’

an example:
docker run -it --name dba1 -v /media/data:/var/lib/mysql/ -p 3306:3306 -d db1

Sorry I could not be of more help :worried:

@dgarstang The path /var/folders/j4/nqyjdv994637sq_l7_d9465h0000gn/T/packer-docker426021951 isn’t shared from OS X and doesn’t exist in the VM. If it exists in OS X, you could try using /private/var/folders/j4/nqyjdv994637sq_l7_d9465h0000gn/T/packer-docker426021951 or you could edit the OS X directories exported in the File Sharing preferences panel by highlighting /private/var/folders and then clicking again to edit the path and change it to /var/folders.

Look out this solution. I was having the same problem:

I have the same problem. Docker desktop for Mac (latest stable) won’t accept ‘/var/lib’ as a path.

When I try ‘docker-compose up’ I get errors like this:
ERROR: for mysql Cannot create container for service mysql: invalid mount config for type “bind”: bind source path does not exist: /var/lib/mydata/mysqldata

Well, I reinstalled docker desktop for Mac, restarted my Mac, cleaned out the app’s data with “Clean / Purge data”, and the above problem is gone. However, I’m now seeing:

ERROR: for livy Cannot start service livy: path /host_mnt/Users/gordonl/n/COMBINEPROJECT/combine-docker/combine/combine is mounted on /host_mnt but it is not a shared mount

I’m confused about how to fix this:
System Preferences?
Command line?
Docker Desktop?

Any help would be appreciated since I’ve been trying to resolve this for a week.

macOS Catalina v10.15.6
iMac (Retina 5K, 27-inch, 2019)

Docker Desktop v2.4.0.0

⇒ docker info
Client:
Debug Mode: false

Server:
Containers: 12
Running: 5
Paused: 0
Stopped: 7
Images: 75
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.19.76-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 1.944GiB
Name: docker-desktop
ID: 5AO5:QDDP:5K2E:3IU6:4YMW:IXEW:3IOB:J7DP:UU4J:NAS6:RHPV:C4TW
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine