I have a devcontainer.json
that looks like this in VSCode:
{
"image": "ghcr.io/mycompany/dev-environment/devcontainer:latest",
"initializeCommand": "docker pull ghcr.io/mycompany/dev-environment/devcontainer:latest"
}
The devcontainer is running on WSL2 and Docker is configured in Windows and integrated with WSL.
This has run plenty of times in the past without issues. Now, when it tries to run the initializeCommand
during the build it returns:
Start: Run: /bin/sh -c docker pull ghcr.io/mycompany/dev-environment/devcontainer:latest
/usr/bin/docker-credential-desktop.exe: Invalid argument
Error response from daemon: Head "https://ghcr.io/v2/mycompany/dev-environment/devcontainer/manifests/latest": denied
If I go straight to WSL and run /bin/sh -c docker pull ghcr.io/mycompany/dev-environment/devcontainer:latest
I can reproduce the error. However, the strange thing is, that if I close WSL and reopen WSL, I can run this command without any issues. However, often times, if I leave the WSL window open and then try to rebuild the container in VSCode, WSL will also start reporting the same error when I run the command.
I can't figure out why it works in WSL, but not when VSCode runs it, and then it will also break my active WSL session as well (but not always). I've checked a couple things changing in the environment variables that might be related, but it doesn't seem to affect anything. I think I have fixed this in the past by running docker login ghcr.io
in WSL, but this time it doesn't seem to work.
EDIT:
I just found out that the command works if run from /mnt/c/Users/myuser
but breaks if I change out of that directory. So I imagine this is some type of issue between my Windows .docker
folder and my WSL ~/.docker
directory. I'm just not sure how to adjust settings on the WSL side to make it always work and to use the Windows credentials.
I'm not sure if this is the best, or correct answer, but it worked.
I went into Docker Desktop for Windows settings and disabled the Enable integration with my default WSL distro
and also disabled integration for the other distros listed there.
I then closed WSL, updated/restarted Docker for Windows, and then re-enabled the settings above. After that, the problem was resolved.
In case it matters, prior to all of this, I also removed the ~/.docker/config.json
and then created a symlink to the windows version: ln -s /mnt/c/Users/myuser/.docker/config.json ~/.docker/config.json