0

New to docker, and as per the documentation about Dockerfile, due to portability, it is not allowed to specify a host volume mapping. That is fine, but is there a way to map a host volume (I am in MAC, so say, my home dir /Users/bsr to /data of ubuntu image) to a linux container. The documentation of docker volume is talking only about docker run, but not sure how to add a volume after creating it.

http://docs.docker.com/userguide/dockervolumes/

2 Answers 2

0

On Linux you can simply mount a directory of your host system to a docker container by passing

-v /path/to/host/directory:/path/to/container/directory

to the docker run command.

You can also see it here in the documentation: https://docs.docker.com/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume

If you are using boot2docker things are more complicated. The problem ist that boot2docker runs a little linux vm to start docker. So if you mount the volume as described above you will mount the directory of the little linux vm.

A workaround for this is described in the README of the boot2docker GitHub page using a samba share:

https://github.com/boot2docker/boot2docker#folder-sharing

2
  • thanks David. that makes sense, but in the same doc, github.com/boot2docker/boot2docker#virtualbox-guest-additions, it says /Users, will be automatically mounted at the location specified:, /Users. But, I don't see any. But, if I specify it in run command ` docker run -d -P -v /Users/bsr/web:/usr/local/web --name web ubuntu, I get access to host folder. so, the question is since run` create a new container, is it possible to specify the -v on an existing container, and say start with start.
    – bsr
    Sep 22, 2014 at 15:43
  • looks like this was in this pull, github.com/boot2docker/boot2docker/pull/534, and may not be available boot2docker 1.2. still digging.
    – bsr
    Sep 22, 2014 at 15:59
0

the following worked, with the help of @sciutand.

git clone https://github.com/boot2docker/boot2docker.git
 cd boot2docker/
 docker build -t my-boot2docker-img .
 docker run --rm my-boot2docker-img > boot2docker.iso
 boot2docker stop
 mv ~/.boot2docker/boot2docker.iso ~/.boot2docker/boot2docker.iso.backup
 mv boot2docker.iso ~/.boot2docker/boot2docker.iso
 VBoxManage sharedfolder add boot2docker-vm -name /Users -hostpath /Users
 boot2docker up
 docker run -d -P --name web ubuntu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.