26

I'm writing code with VSCode from inside a VSCode container.

I can open terminals inside the dev container, but I can't figure out how to open a (VSCode integrated) terminal in my local machine.

I can of course open a separate terminal application like iTerm2, but it's far more convenient to use VSCode's integrated terminal panel. Is opening a local terminal possible with VSCode dev containers?

4
  • 1
    I don't think that's possible. But could you maybe ssh from the dev container to your local machine? Commented Feb 17, 2022 at 8:23
  • @carlfriedrich Yeah that's true. Not as convenient, but should be possible. Commented Feb 17, 2022 at 16:33
  • I have posted an answer to make this more convenient. Commented Feb 17, 2022 at 17:55
  • Did that work for you? Commented Feb 23, 2022 at 8:35

2 Answers 2

42

This solution is provided in the Accepted Answer on this SO question, so if the below helps, go and upvote that.

Using the command palette (default ctrl+shift+p/cmd+shift+p), there is an option

Terminal: Create New Integrated Terminal (local)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Just tested it, works great. idk how I missed this, thanks.
Doesn't work on macOS unfortunately, since VS Code expects bash to live at /usr/bin/bash, but it actually lives at /bin/bash. No amount of fiddling with the VS Code terminal settings seemed to fix this for me...unless I just didn't try hard enough shrugs
6

Provided that you have key-based SSH access from the container to the host, you can add a terminal profile to your remote settings (run command Preferences: Open Remote Settings (JSON) (Dev Container) to open them):

{
    "terminal.integrated.profiles.linux": {
        "bash (Host)": {
            "path": "ssh",
            "icon": "terminal-bash",
            "args": [
                "user@host",
            ],
        },
    },
}

This will get you an according bash (Host) entry in your "Add Terminal" drop-down menu:

enter image description here

1 Comment

This answer helped me to open my SSH terminal from Devcontainer. It is really good

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.