mount a host volume to a container created through Dockerfile
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
/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.
2 Solutions collect form web for “mount a host volume to a container created through Dockerfile”
On Linux you can simply mount a directory of your host system to a docker container by passing
to the docker
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:
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