user504909
user504909

Reputation: 9549

How to use -v volumes parameter in docker on Windows Subsystem for Linux

My windows 10 version is 1803

I install docker fellow the link:

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

I try to use -v of docker like:

docker run -it -v ~/.aws:root/.aws/ ubuntu

I also try to use:

docker run -it -v $(realpath ~/.aws):/root/.aws ubuntu

But I find the volumes I want to mapping to docker system is not there.

when I do:

ls /root/.aws

there is always empty, how to mapping the data volumes on Windows Subsystem for linux?

Upvotes: 4

Views: 8791

Answers (3)

pnocti
pnocti

Reputation: 97

Answer above by Serge works, but I have done away with the cmd.exe part and just enclosed the Windows style path with single quotes.

I have the same issue with Docker for Desktop running inside WSL not reading my ~/.aws folder. My .aws folder is a soft link from C:\Users\.aws folder.

This is what worked for me:

docker run -v 'C:\Users\username\.aws':/root/.aws linux_image

Upvotes: 3

Serge Owona Okoa
Serge Owona Okoa

Reputation: 1

This question is a bit old but I had the same issue. Below is my configuration:

  • Host OS: windows 10.0.17134 N/A Build 17134
  • WSL:
    • 4.4.0-17134-Microsoft #706-Microsoft
    • Ubuntu 18.04.1 LTS
  • Docker:
    • Docker-ce on WSL: Docker version 18.09.6, build 481bc77
    • Docker for Windows ce: Version 2.0.0.3 (31259) build 8858db3

The following solution is mostly useful when working on your own laptop with docker as a development environment. Shouldn't be used in production/test servers:

  1. Share a folder between WSL and and Windows 10.
  2. Copy the files needed to be shared with docker containers to the shared folder. This allows the files to be visible/accessible to both WSL and Windows 10.
  3. start a docker container binding a volume using the windows style volume name

Below are the commands:

  1. On Windows Host machine, create a folder on the windows machine

    md %USERPROFILE%\dockerVolume
    
  2. On WSL link that folder with the on the WSL user home folder

    ln -s `wslpath $(cmd.exe /C "echo %USERPROFILE%")|sed -e 's/\r//g'`/dockerVolume $HOME/dockerVolume
    
  3. On WSL copy all the files you need to access from the Docker container in $HOME/dockerVolume
  4. Then run you docker container as:

    docker run -it -v `cmd.exe /C "echo %USERPROFILE%"|sed 's/\r/\\\dockerVolume/g'`:/dockerVolume -w /dockerVolume --entrypoint /bin/bash <DOCKER IMAGE NAME>
    

Upvotes: 0

Rich Turner
Rich Turner

Reputation: 11014

Docker for Windows runs atop Windows itself but has no knowledge of WSL.

In WSL:

  • Distros can see the contents of Windows "drives" via the automatically mounted drives under /mnt/<drive-letter>
  • Windows currently cannot reach into the filesystems of installed Linux distros. We're working to remedy this in future releases ;)

While Docker Engine itself cannot run within WSL, you can install Docker for Windows, and operate it from within WSL using the docker command-line tool, specifying the hostname via the -h argument, or export to DOCKER_HOST in your .bashrc.

You may find some of these tutorials useful:

Upvotes: 6

Related Questions