Access windows host folders from docker container

Hi All,

Currently, I am using Docker Desktop for Windows to run Ubuntu images. I am using WSL2 as Linux subsystem. Now, I want to do some ssh actions from the docker container. There are multiple containers and I want to use same ssh keys for all those containers. this is only for development activities and may not be suited for production due to security reasons. I want to store my ssh keys on Windows host and access them from the container. Is this possible with Docker and WSL2? Can I do it within the dockerfile? I have a basic dockerfile which creates an ubuntu image. If anyone has done this, please let me know.

Your help will be much appreciated.

Thanks in advance.

You present two scenarios here–> 1. Getting the ssh keys into the image during the build process, or 2. accessing the keys in a shared location on the Windows host while the containers are running. For option 1, you could simply use the ADD or COPY command in your Dockerfile to pull in the ssh keys from whatever location you want during build. For option 2 you could keep the ssh key in a shared location on the Windows host and mount that same location inside each running container, using the -v flag. For example: docker run -it --name containerName -v C:\SharedWindowsFolder:/location/in/container imageName:tag