0

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.

1 Answer 1

1

My guess is that you haven't done is with this particular location/drive. You need to allow docker to access it.

Here is how (for windows)

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

  1. 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

Sign up to request clarification or add additional context in comments.

1 Comment

I had seen the shared folder, and it still appeared to be shared. However, my password had changed and I needed to reset/update the credentials. This involved clicking 'Reset Credentials' in the settings/shared drive tab, which unshared the drive, then sharing it again by clicking the box and entering the new password. Then everything works. Thank you for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.