I am using Docker Toolbox for Windows. Everything works fine. I am now trying to run an image which clones some github repos into the local container folders.
What I want now is to mount that container folder (containing the files) to a folder on my host machine. I am trying to do it like this:
docker run --name testcontainer -v /c/Users/username/Desktop/testvolume:/var/www/testsite -d -p 80:80
It is correctly creating the folder on my host, but it is empty and its overwriting the contents of the directory in the container, so it gets emptied as well.
Why does it not work as expected, and how can I achieve this?
Its because the host is master, so if you mount from the host, it will be the hosts data that will be available in the container.
So, either put the data in the image ( as i guess you did there ), and for every change, create a new version of the image.
Or you could create the image as a application only, and mount the webdata to the container ( as you did ), so the data always is on the host.
yes, the data is in the image. I am cloning a git repo into /var/www/testsite when building the image. This is the Code I need to available in my development environment. So I want to mount it to my host system. How can I achieve this?
If you want to do it this way, you could replace the CMD/RUN in your image with a script.
Example steps in your Dockerfile:
1- Clone your repo into /var/tmp/
2- Create a bash script, that copies the files from /var/tmp to /var/www
3- At the end of the script, put your previous CMD
4- Use this new script as the start script for the container.
If, you want me to elaborate, you need to provide your Dockerfile
Tested it and built a fresh image with the code like you proposed. Sadly with the same result. The folder is empty on host and container. When not mounting the folder to the host, the folder in the container has all the files and works correctly.