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

Allow vscode to attach to containers (specifically Podman) running inside a WSL2 instance #5504

Closed
OmanF opened this issue Jul 23, 2021 · 10 comments
Assignees
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster

Comments

@OmanF
Copy link

OmanF commented Jul 23, 2021

I'm running a WSL2 Ubuntu instance, itself running a Podman container. I would like to edit the code inside the container.

Using the remote development extensions I can only get the Attach to WSL option, but, as mentioned, the code resides in the container running inside the instance.

I know that once connected to WSL I have the option to Reopen folder in a dev container, but that:

  1. Builds a new container, not reusing the container I've already set up myself.
  2. Build a Docker-compatible container, while Podman is rootless container management, meaning, even if I'm willing to forgo clause (1), the dev container doesn't get installed on the WSL instance, as Podman has no root permissions.

Trying to directly choose Remote - connect to a container simply doesn't recognize the container (logically so, since it's on a logically different machine, the WSL instance).

I would like that when I remote connect to a WSL instance, I can click the green, double-arrowed, "Connect to remotes" button and have the possibility to connect to containers running within that WSL instance (allowing me to use my own, Podman managed, containers, not pre-built, Docker-managed, dev containers).

Thank you.

@aeschli aeschli assigned chrmarti and unassigned aeschli Aug 17, 2021
@chrmarti
Copy link
Contributor

Could you try changing the Remote > Containers: Docker Path setting to podman and check if F1 > Remote-Containers: Attach to Running Container... shows your container?

image

@chrmarti chrmarti transferred this issue from microsoft/vscode Aug 24, 2021
@chrmarti chrmarti added containers Issue in vscode-remote containers info-needed Issue requires more information from poster labels Aug 24, 2021
@DougHaigh
Copy link

Due to the recent change in the Docker license/fees, I installed podman in my WSL2 Ubuntu image. I have podman running my dev container (my-dev-container) in WSL2 also. I have made the change you stated so that 'podman' is my docker path.

From WSL2 command prompt I run 'code .' and VSCode (Windows) comes up. I select 'Remote-Containers: Attach to running container' and it shows the podman container (my-dev-container). I select it.

It starts another VSCode window and pops up the error 'Cannot attach to the container with the id/name my-dev-container, it no longer exists along with the options 'Chose Container', 'More Actions' and 'Close Remote'. I select the 'Chose Container' and it pops up an error 'Docker version 17.12.0 or later required'. Repeat the process and select 'More Actions' and see 'Chose container' and it gives the same error. I believe the error is because there is no 'podman.exe' even though I am running in a WSL2 window.

How can it connect to the running container and develop code in it?

@chrmarti
Copy link
Contributor

chrmarti commented Sep 6, 2021

@DougHaigh I have created #5550 to track your issue which seems to be different to the one reported here. Thanks.

@OmanF
Copy link
Author

OmanF commented Sep 7, 2021

Sorry for taking a while...
As the screencast shows, the suggested way of operating didn't solve the issue.

BTW, since Podman is actually installed on the WSL2 instance, I also tried a Connect to Distro, connected to the WSL2 instance with the Podman installed and then tried clicking the remote connection button (green, double-arrows)... it still didn't even so much as offer to connect to an image, only install a dev-container (this part is not on the screencast).

2021-09-07_20h28_09.mp4

@chrmarti
Copy link
Contributor

chrmarti commented Sep 8, 2021

@OmanF Make sure you have a folder open in WSL when trying to attach. (Tracked as microsoft/vscode#111371.)

@OmanF
Copy link
Author

OmanF commented Sep 8, 2021

I'm not really sure what having a folder open in WSL is?

At any rate, I tried the following:

  1. On VSCode open a folder, namely Desktop, then try to connect to running container -> Same issue as in the previous screencast, i.e., prompted to install Docker Desktop.
  2. On VSCode open the WSL folder (\\wsl$\<machine>) folder, then try to connect to running container -> same.
  3. On VSCode open my WSL user's home directory, then try to connect -> same.

Looks like the issue is that, although I changed the settings as you described in a previous screenshot, so my Docker path says podman, this is not being respected, or, despite the WSL folder being open, it can't find the podman executable on WSL...

Edited: Adding a screencast.

2021-09-09_06h49_12.mp4

@chrmarti
Copy link
Contributor

Got it, the case using a \\wsl$\<machine> path wasn't fully covered. Fix will be in the next Remote-Containers release (will initially require VS Code Insiders).

@OmanF
Copy link
Author

OmanF commented Sep 10, 2021

Great! Thank you very much! Using Podman inside WSL2 instance, all from a Windows VSCode will make my flow that much neater on the filesystem.

Looking forward to it.

@PavelSosin-320
Copy link

Unlike Docker, there are 2 options to communicate with Podman:

  1. Locally, via native Podman CLI.
  2. Remotelly via Podman remote. To use this option it is necessary to start Podman service listening to TCP port using Podman system service IP:port. manually as root or in the regular GUI session as rootless user. Tiny Systemd unit can help you:
    [Unit]
    Description=PodmanAPI Service for root or Rootless users
    Documentation=man:podman-system-service(1)
    Requires=server.slice
    After=server.slice
    StartLimitIntervalSec=0
    [Service]
    Type=simple
    KillMode=process
    Environment=LOGGING="--log-level=info"
    ExecStart=/usr/bin/podman system service -t 0
    ExecReload=/bin/kill -- $MAINPID
    PIDFile=$XDG_RUNTIME_DIRECTORY/podman/podman.pid
    Please, use only the recent Podma version 3.3.1 because the previous one contains critical bug.

@chrmarti
Copy link
Contributor

This might also help: I have added a user setting to always run commands in WSL, also for Windows paths and when there is no local path when attaching to an existing container (#5539).

@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers Issue in vscode-remote containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants