Reputation: 25
I'm trying to get a Linux container to share files with the Windows host, primarily because I want to build some Linux libs, and put the resulting output where I can see them in the file system. I open a cmd.exe window and do the following.
Microsoft Windows [Version 10.0.16299.1565]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\alanmur>mkdir \dev\test
C:\Users\alanmur>cd \dev\test
C:\dev\test>echo for the container >> testfile.out
C:\dev\test>dir
Volume in drive C has no label.
Volume Serial Number is 0C3F-DCE2
Directory of C:\dev\test
2020-01-07 21:45 <DIR> .
2020-01-07 21:45 <DIR> ..
2020-01-07 21:45 20 testfile.out
1 File(s) 20 bytes
2 Dir(s) 52,950,069,248 bytes free
C:\dev\test>docker run -it --rm -v C:/dev/test:/app/data:rw alpine /bin/sh
/ # cd /app/data
/app/data # ls
/app/data # echo for the host >> testfile2.out
/app/data # ls
testfile2.out
/app/data # exit
C:\dev\test>dir
Volume in drive C has no label.
Volume Serial Number is 0C3F-DCE2
Directory of C:\dev\test
2020-01-07 21:45 <DIR> .
2020-01-07 21:45 <DIR> ..
2020-01-07 21:45 20 testfile.out
1 File(s) 20 bytes
2 Dir(s) 52,942,929,920 bytes free
C:\dev\test>
How would I set this up so that the first ls
on the container shows testfile.out and then when I exit the container I can see testfile2.out in the host C:\dev\test directory? I swear I had this working before, but I can't figure out what I'm doing wrong now, as I am doing everything the same.
Upvotes: 0
Views: 106
Reputation: 5702
My guess is that you haven't done is with this particular location/drive. You need to allow docker to access it.
For you it is drive C:
In the System Tray, you should have the cute Docker whale swimming. Right click and select Settings.
Docker Settings Menu
- In the Settings dialog that comes up, click on Shared Drives. This should be able to list down the drives that you have available on your Windows machine. In my case, I have C and D drives and I have chosen to share D:\ drive since I want to expose the D:\data folder to my containers.
Docker for Windows : Shared Drives 3. 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.
Source: https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c
Upvotes: 1