Mounting Volumes in Boot2Docker on Hyper-V
Docker is awesome for development. However, when sharing volumes with Boot2Docker things don’t quite behave as expected (i.e. it doesn’t work). Here’s how to work around this on Windows.
Since containers are intended to be immutable this isn’t really a problem for production, but in development we want to be able to mount our code in the container to enable a faster turnaround in the development process, that is we need to edit files and see the results immediately.
Unfortunately, Boot2Docker does not currently mount the Windows files which means when you try to mount a voulme using the ‘–volume’ (or ‘-v’) option you end up with an empty drive.
I use this little script to mount my current directory on the Boot2Docker guest. This only needs to be run once for each Docker host you create.
Note that the folder you want to mount must be shared on Windows. Your Home directory is automatically shared, but if you are outside that directory you will need to share it.
Once you have run this you cn mount directories as normal, e.g. here’s how I run my Jekyll container:
Note the extra ‘/’ before ‘$PWD’ in this command. This isn’t needed on Linux.
We could replace the interactive part of this with parameters but since this only needs to be run once I don’t usually bother with that.
If (like me) you have all your project files in a single directory then you could simply share that directory when you first create the Docker host.
- Does this problem exist on Linux hosts for Boot2Docker?
- Is this something that should be included in Boot2Docker or Docker Machine?
- Searching for a Cure for Cancer with Docker and Azure
- Load Balancing for Docker Containers with HA Proxy
- Readme Files That Are Also Slide Decks
- Create a Simple Swarm Cluster on Azure with ARM
- Getting Started With Docker Swarm on Azure
- Simple Load Balancing for Docker Containers
- Install Docker and Docker Machine
- Using Docker Machine to create a Docker Host on Azure
- Experiments With Development Using Docker
- Dockerizing a Jekyll Site