Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Last active November 11, 2023 01:22
Show Gist options
  • Star 72 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save codeinthehole/7ea69f8a21c67cc07293 to your computer and use it in GitHub Desktop.
Save codeinthehole/7ea69f8a21c67cc07293 to your computer and use it in GitHub Desktop.
How to share folders with docker containers on OSX

How to share a folder with a docker container on OSX

Mounting shared folders between OSX and the docker container is tricky due to the intermediate boot2docker VM. You can't use the usual docker -v option as the docker server knows nothing about the OSX filesystem - it can only mount folders from the boot2docker filesystem. Fortunately, you can work around this using SSHFS.

Install sshfs on the boot2docker machine:

$ boot2docker ssh
docker@boot2docker:~$ tce-load -wi sshfs-fuse

and create a folder to mount to:

docker@boot2docker:~$ mkdir ~/osx

Ensure that 'Remote Login' is enabled in 'System Preferences > Sharing' and make a note of your host IP address.

Now run sshfs on the boot2docker VM to mount a folder from your host machine:

docker@boot2docker:~$ sudo sshfs $username@$ipaddress:/Users/$username/ /home/docker/osx/

replacing $username and $ipaddress as appropriate. You'll have to enter your password.

Now you can run a docker container (using the docker client on your host machine) and mount a local folder (using the path to it on the boot2docker VM), eg:

$ docker run -it -v /home/docker/osx/somefolder:/opt/somefolder ubuntu bash

and any updates made within your local folder will be immediately visible within the container.

Largely taken from the comments here: boot2docker/boot2docker#188

@Blizzke
Copy link

Blizzke commented Feb 6, 2016

404 for the sshfs-fuse install here as well. Getting a bit irritated by how much work this is, simply to get a folder mounted

@anupvarghese
Copy link

With native OSX app, it can be done easily as follows,

To pull a new docker image (optional step)
docker pull ubuntu

Make volume share as below,
docker run -t -i -v $(pwd):/home/shared ubuntu /bin/bash

@ReaddyEddy
Copy link

Agreed this worked for me
docker run -it -v /Volumes/volname:/volname image-id /bin/bash

@inancgumus
Copy link

inancgumus commented May 14, 2017

How about mounting a volume from a different docker-machine to a local docker host? Such as a docker-machine running in digitalocean droplet to my macbook?

@pilgrim2go
Copy link

Thanks @fyddaben @codeinthehole: it works for me

@danvc
Copy link

danvc commented Jun 12, 2017

Hi Guys, I did the inverse and worked faster with less steps to get it working:

https://github.com/DanZeuss/DockerOnMacOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment