Docker WSL issues with local file permissions and git integration

I am attempting to run a Docker container on Windows with WSL (Debian 2). Within the container, I want to access and edit files I have stored locally (pulled from a remote GitHub repository). However, I am running into issues with file permissions.

For context: In order for the container to work, I need to clone down a repository from GitHub which contains extensions enabling usage across softwares (i.e., Python, git,git-lfs), and a bash script which runs the container from a built image on DockerHub (where each of these softwares are installed when building the image, through the Dockerfile).

Currently, the production workflow is as follows:

  1. I open a Windows powershell and clone down a GitHub repository (the contents will serve as the skeleton for our container).
  2. I initiate WSL (Debian 2) in the terminal and execute a bash script stored in the local repository to pull the relevant image and run the container in Docker with some pre-specified volumes.
  3. Within the Docker container, I execute some interactive code using some of the above softwares which are installed in the container through the Dockerfile.

To my understanding, each of these environments (Windows, WSL Debian 2, and interactive code in the container itself) is essentially operating as a distinct environment. I am running into issues relating to file permissions across these spaces (or at least the below screenshot from Docker support suggests this might be the issue):

As a result of these permission errors, I am not able to pull or push down new elements of the repository which was cloned down locally when working within Debian or when running interactive code within a Docker container. The specific error message I run into is: detected dubious ownership in repository. I am prompted to modify: git config --global --add safe.directory <repo_name>, however I am unable to do this within the Docker container.

Any suggestions on how to proceed here would be much appreciated. I am happy to expand with further details.

So you are actually not using Docker Desktop as it in the category of this topic, but Docker CE in a WSL distribution. In that case, the best solution would be to clone your repository on WSL, not on the Windows host and use the same filesystem. Note that when you mount files in WSL from your Windows host, reading and writing those files will be slower than doing the same on the WSL distribution’s filesystem.

1 Like