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 /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/

  • Docker centos7 systemctl deos not work : Failed to connect D-bus
  • Docker-machine's container contact application on Mac host
  • WordPress inside docker container behind nginx proxy with ssl
  • Docker event output formatting
  • Consul for Docker container discovery: how to get latest container in Consul-Template?
  • Passing arguments to service in docker-compose.yml
  • Failed to start docker.service: Unit docker.service is masked
  • ctrl+G in erl doesn't work
  • How to get IP address of running docker container
  • What's the point of data-only docker containers?
  • Docker container cannot access network
  • Adding files to standard images using docker-compose
  • 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

    -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

    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.