I have make my code ready on Windows, but I find it's not easy to share to boot2docker.
I also find that boot2docker can't persistent my changes. For example, I create a folder, /temp
, after I restart boot2docker. This folder disappears, and it's very inconvenient.
What is your way when you have some code on Windows, but you need to dockerize them?
---update---
I try to update the setting in VirtualBox and restart boot2docker, but it's not working on my machine.
docker@boot2docker:/$ ls -al /c total 4 drwxr-xr-x 3 root root 60 Jun 17 05:42 ./ drwxrwxr-x 17 root root 400 Jun 17 05:42 ../ dr-xr-xr-x 1 docker staff 4096 Jun 16 09:47 Users/
In the System Tray, you should have the cute Docker whale swimming. Right click and select Settings.
Click on Apply. This will bring up the Credentials dialog and you will need to provide your current Windows credentials. Ensure that you give it correctly. I also suspect that you might need to be an administrator.
To mount our host directory (C:\data) in a container, we are going to use the
-v
(volume) flag while running the container. A sample run is shown here:I have CentOS in my local Docker container.
Boot2Docker is a small Linux VM running on VirtualBox. So before you can use your files (from Windows) in Docker (which is running in this VM), you must first share your code with the Boot2Docker VM itself.
To do so, you mount your Windows folder to the VM when it is shutdown (here a VM name of
default
is assumed):(Alternatively you can also open the VirtualBox UI and mount the folder to your VM just as you did in your screenshot!)
Now
ssh
into the Boot2Docker VM for the Docker Quickstart Terminal:docker-machine ssh default
Then perform the mount:
sudo mkdir /VM_share
sudo mount -t vboxsf win_share /VM_share
After that, you can access
C:/work
inside your Boot2Docker VM:Now that your code is present inside your VM, you can use it with Docker, either by mounting it as a volume to the container:
Or by using it while building your Docker image:
Mount shared folder Windows guest with Linux host (vm name 'default'):
Shutdown 'default' VM:
Add shared folder command line:
Start VM (headless only command line interface):
Connect to ssh:
Create VM sharedfolder directory:
Mount Windows folder to host VM:
Using Docker Toolbox, the shared directory can only be
/c/User
:Enter image description here
Step1&Step2 Command in the "Docker Quickstart Terminal" in the implementation of Step1 & Step2 can be:
Then restart the VM. Try this:
docker run --name php-fpm --rm -it -v /e:/var/www/html php:7.1.4-fpm /bin/bash
References:
See this answer.
I have Windows 10 Home edition with Docker toolbox 1.12.2 and VirtualBox 5.1.6.
I was able to mount a folder under
C:\Users
successfully in my container without doing any extra steps such asdocker-machine ssh default
.Example:
So having your files under
C:\Users
probably is the simplest thing to do.If you do not want to have your files under
C:\Users
, then you have to follow the steps in the accepted answer.