Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcontainer doesn't work on a folder mounted in WSL #10301

Open
ThePlenkov opened this issue Sep 22, 2024 · 12 comments
Open

Devcontainer doesn't work on a folder mounted in WSL #10301

ThePlenkov opened this issue Sep 22, 2024 · 12 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote)

Comments

@ThePlenkov
Copy link

Hi,

Let me please explain the situtation:

  • I have workspace with all projects stored in the external ext4 vhdx file
  • I have mounted it via wsl --mount command to all wsl distros wsl --mount --vhd "$PSScriptRoot\ws.vhdx" --partition 1 --name workspace
  • When I "Open in container" from /mnt/wsl/workspace/myapp folder container starts but filetree is empty

However when I run a command like this:

docker run -it --rm --mount "source=$(pwd),target=/workspace,type=bind" ubuntu bash

all the files are shown, and changes in that folder are attracted in my workspace folder in WSL ( which is mounted vhdx )

So I make the assumption that something is wrong here with how VS code is binding this folder to a devcotnainer

@ThePlenkov
Copy link
Author

here is my devcontainer.json

{
  "name": "Node.js & TypeScript",
  "workspaceFolder": "/workspace",
  "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
  "build": {
    // Path is relative to the devcontainer.json file.
    "dockerfile": "Dockerfile"
  }

i tried with workspace mount and wihtout..

@ThePlenkov
Copy link
Author

ThePlenkov commented Sep 22, 2024

Actually, I have inspected created devcontainer and see there that my source folder is something like mnt/wsl/workspace/git_projects/myapp and I used to work in a symlinked folder ~/git_projects/myapp which is pointing to /mnt/workspace..

And what is very interesting.
This command works in :

:~/git_projects/fs-observability-aws$ docker run -it --rm --mount "source=$(pwd),target=/workspace,type=bind" ubuntu ls /workspace

and this not

cd  cd $(realpath $(pwd))
docker run -it --rm --mount "source=$(pwd),target=/workspace,type=bind" ubuntu ls /workspace

I honestly do not have any explanations why.

@vs-code-engineering vs-code-engineering bot added the wsl Issue in vscode-remote WSL label Sep 22, 2024
@ThePlenkov
Copy link
Author

OK a bit more updates:

What I noticed - that if I use dockerfile directly - it's always mounting real path like /mnt/workspace ..

However when I switched to compose - it started using the path /home/pplenkov/git_projects/myapp:/workspace:rw with symlink and it started working as expected:

So most likely this is the issue for docker itslef why it happens like this.

@ThePlenkov
Copy link
Author

So may be what can be improved for VS Code extension - do not resolve to real path the path which we use for binding the workspace in WSL if Dockerfile is used.

@aeschli aeschli assigned chrmarti and unassigned aeschli Sep 23, 2024
@chrmarti
Copy link
Contributor

Which path do you get for pwd in a terminal in this folder in VS Code in WSL?

@chrmarti chrmarti added containers Issue in vscode-remote containers info-needed Issue requires more information from poster and removed wsl Issue in vscode-remote WSL labels Sep 27, 2024
@ThePlenkov
Copy link
Author

It depends.. if open from ~/path then is /home/myuser/path

While at same time if I go to /mnt/wsl/path - it will be same folder

Because of symlink.

I think it should be possible to reproduce in any wsl since mnt/c is available everywhere

@ThePlenkov
Copy link
Author

I also found another problem. If docker compose is running only from symlinked folder ( which is most likely docker issue )

If I go to typescript debugging- all my links are broken and sourcemaps do not work - they all resolved against real path

While if I go to real /mnt path - I can debug from that project, but cannot mount to docker 😞

@ThePlenkov
Copy link
Author

What I noticed also, I added following section:

  "remoteEnv": {
    "hostLocalWorkspaceFolder": "${localWorkspaceFolder}",
  }

so in the container - it's always a real path, but docker uses different bound types when binding from symlinked folder .

It's hostFile in one case and wsl2DistroFile in another.

I described it also here: docker/for-win#14380

@ThePlenkov
Copy link
Author

What could probably help is to use: ${localEnv:PWD} instead of ${localWorkspaceFolder}, but it doesn't work. always empty

@ThePlenkov
Copy link
Author

ThePlenkov commented Oct 25, 2024

@chrmarti do you think it is possible to change the logic of localWorkspaceFolder and to use the actual host OS path, not resolved realpath? Or may be we can introduce one more variable to avoid regression issue.

@FloSch62
Copy link

FloSch62 commented Dec 5, 2024

I having the same problem I would like my devcontainer.json to be

"workspaceFolder": "${localWorkspaceFolder}",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind"

as I need it for orbstack and so, but on Windows it only works if I do:

"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind"

But that workaround for windows, does than not work anymore in orbstack and others.... And I would like not to maintain two devcontainer files...

@chrmarti chrmarti added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Dec 9, 2024
@chrmarti
Copy link
Contributor

This seems to be a Docker issue: docker/for-win#14380

@chrmarti chrmarti added the upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote) label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers upstream Issue identified as 'upstream' component related (exists outside of VS Code Remote)
Projects
None yet
Development

No branches or pull requests

4 participants