How to share a folder between my Mac and a Docker container

10,599

Solution 1

You should use Docker for Mac. No VirtualBox required and the filesystem access is a lot more natural as well.

More details at https://www.docker.com/products/docker#/mac.

Solution 2

There are many ways to do it, and one of the easier ways is:

Step 1: Make sure Docker.app has an entry for that folder/volume

enter image description here

Step 2: Mount it with the -v flag and the path to that folder:

docker run --link cockroachdb -v /Users/gajensunthara/backups:/Users/gajensunthara/backups -it --rm --name backup-restore backup-restore
Share:
10,599
evanmcd
Author by

evanmcd

Senior level technologist/team leader with more than 15 years experience in a fast-paced environment. Possibly addicted to the craft of programming, and passionate about using technology to create solutions that help affect a positive change in the world.

Updated on June 04, 2022

Comments

  • evanmcd
    evanmcd almost 2 years

    Been spending some time trying to setup a Docker container with access to a folder on my Mac.

    I know that you can use Docker Volumes to connect to a folder in the host, which on Mac ends up being Linux in VirtualBox, with the -v argument to docker run.

    And given that, I figured that I could setup a shared folder in VirtualBox, which could then be mapped to the Docker container.

    However, I've not been able to get the Shared Folder I've added to VB to show up.

    Here's what I've done:

    1) Added a Shared Folder in the VB admin

    VirtualBox Shared Folder config

    2) Restarted the VB OS with both docker-machine restart and via the VB app itself

    3) Logged into the VB OS via docker-machine ssh

    4) Did an ls -l of the root directory

    The Users folder (which was there already in VB) shows up, but the folder I added (Projects) does not.

    I can't figure out any reason why both folders would not appear. Anyone else having this problem?

    Seems like with so many people talking about doing local Development with Docker, and so many devs using Macs, this would be a simple problem. But... alas...not for me so far.

    Thanks for any help.