Boot2Docker on Mac - Accessing Local Files

后端 未结 4 978
失恋的感觉
失恋的感觉 2020-12-09 18:56

I\'ve just set up boot2docker on my Mac. How do I go about mounting a local directory on my Mac so that it\'s accessible all the way through to a running Docker container? T

4条回答
  •  佛祖请我去吃肉
    2020-12-09 19:52

    As Levi mentioned, the /Users directory is auto-mounted. This is true in both boot2docker and docker-machine. That said, if you want to mount anything outside of /Users, all the current answers talk about Boot2docker. Since that's now deprecated in favor of docker-machine, this works for docker-machine:

    First, ssh into the docker-machine vm and create the folder we'll be mapping to:

    docker-machine ssh $MACHINE_NAME "sudo mkdir -p \"$VOL_DIR\""
    

    Now share the folder to VirtualBox:

    WORKDIR=$(basename "$VOL_DIR")
    vboxmanage sharedfolder add "$MACHINE_NAME" --name "$WORKDIR" --hostpath "$VOL_DIR" --transient
    

    Finally, ssh into the docker-machine again and mount the folder we just shared:

    docker-machine ssh $MACHINE_NAME "sudo mount -t vboxsf -o uid=\"$U\",gid=\"$G\" \"$WORKDIR\" \"$VOL_DIR\""
    

    Note: for UID and GID you can basically use whatever integers as long as they're not already taken.

    This is tested as of docker-machine 0.4.1 and docker 1.8.3 on OS X El Capitan.

提交回复
热议问题