How to mount a host directory in a Docker container

后端 未结 25 1613
庸人自扰
庸人自扰 2020-11-22 12:43

I am trying to mount a host directory into a Docker container so that any updates done on the host is reflected into the Docker containers.

Where am I doing somethin

25条回答
  •  野性不改
    2020-11-22 13:21

    2 successive mounts: I guess many posts here might be using two boot2docker, the reason you don't see anything is that you are mounting a directory from boot2docker, not from your host.

    You basically need 2 successive mounts:

    the first one to mount a directory from your host to your system

    the second to mount the new directory from boot2docker to your container like this:

    • 1) Mount local system on boot2docker

      sudo mount -t vboxsf hostfolder /boot2dockerfolder
      
    • 2) Mount boot2docker file on linux container

      docker run -v /boot2dockerfolder:/root/containerfolder -i -t imagename
      

    Then when you ls inside the containerfolder you will see the content of your hostfolder.

提交回复
热议问题