angulardockercontainersmountunison

How do I bind a folder from a docker container to Windows?


High High,

I have a very specific problem here & 3 days of searching hasn't helped.

I have a docker file running my (enviroment) so to speak, currently it sets the container up, downloads the repo from git and cd's (WORKDIR) into said folder. It then does an NPM start (angular2) and forwards the port to my host (so I can see the localhost:4200 on my host browser).

All of this is pretty neat, except the final missing piece. I want to "mount & bind" the repo folder to windows (host machine) so that I can grab the code, edit it there.

I have tried using -v (host_path):(container_path) during docker run [image-name] but that produces an error where the container exits immediately after starting with code 254 (???????) and yes that's with me using -d (detached mode)

In fact here is my entire run command..

docker run -dt -it --publish 4200:4200 --privileged -v (host_path):/(container_path) [image-name]

... I've tried this approach Other Stack Solution which is basically mounting and or binding the folder inside the container after running it which was successful to an extent. I don't know where the /mnt/test directory exists (it seems to be nonexistent) on the host machine.

Other things I've tried include Unison Rsync which is beyond frustrating to say the least because I don't think it has an idea that the other argument is a host path.

Please help if you can!

Here is a pic of how it exits when doing -v during docker run


Solution

  • Since you are using windows and docker, it means docker uses VirtualBox to run your containers "so to speak".

    Docker Toolbox expects that your data volumes will be within C:\Users

    To add new locations, you need to go to your VirtualBox manager => setting of your (probably default) image => shared folders, and add the path you want to mount (host_path)

    enter image description here

    Also take a look at this guide for more information about mounting inside the docker-machine as an alternative: link