How to mount existing Windows host directory in docker conatiner running inside WSL2?

Hello All,

I am trying to setup docker container in my Windows machine with WSL2 (ubuntu ) without docker desktop . The aim is to use Windows machine ssh keys inside the docker container. I followed a tutorial Volume Mounting SSH Keys into a Docker Container and below is my script

set -e

cp -R /tmp/.ssh /root/.ssh
chmod 700 /root/.ssh
chmod 644 /root/.ssh/
chmod 600 /root/.ssh/id_rsa

exec "$@"

Now, when I try to run the container like this:

docker run -it -v /c/Users/<name>/.ssh:/tmp/.ssh:ro my_image

I always get chmod: cannot access '/root/.ssh/': No such file or directory

I have tried different options like:


Also, when I cd //c/Users/<name>/.ssh (within WSL2) there is no file.

But nothing seems to work for me.

Has anyone be able to mount windows folder as bind volume? Can anyone please let me know what is the issue here?

Thanks in advance

P.S: I am working with WSL2 (WSL version: and Windows version: 10.0.22621.755) Please let me know if any info is missing

You path is wrong. You can dynamically resolve the user profile path and convert it to a valid wsl path:

# output: /mnt/c/Users/<name>/