VSCode's remote-containers lets you connect to containers, either containers set up on another machine or set up locally. It makes it much easier to set up the networking so that you don't have to configure all the ports. If you're learning Docker, VSCode makes it so much easier. It has a few quirks, especially if you're running it on Windows with Docker Desktop/WSL2, but if you pair it with the Docker VSCode extension, it becomes incredibly easy to learn. Answer from Willbo on reddit.com
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › containers
Developing inside a Container
November 3, 2021 - Start VS Code and run Dev Containers: ... (F1). Enter microsoft/vscode-remote-try-node (or one of the other "try" repositories), a Git URI, a GitHub branch URL, or a GitHub PR URL in the input box that appears and press Enter...
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Dev Containers - Visual Studio Marketplace
Extension for Visual Studio Code - Open any folder or repository inside a Docker container and take advantage of Visual Studio Code's full feature set.
🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › develop-remote-host
Develop on a remote Docker host
November 3, 2021 - Follow the quick start for the Remote - SSH extension to connect to a host and open a folder there. Create a devcontainer.json file. Use the Dev Containers: Reopen in Container command from the Command Palette (F1, ⇧⌘P (Windows, Linux Ctrl+Shift+P)).
🌐
Rancher Desktop
docs.rancherdesktop.io › vs code remote containers
VS Code Remote Containers | Rancher Desktop Docs
The [Visual Studio Code Remote - Containers] extension lets you use a Docker container as a full-featured development environment, which helps ensure a consistent environment across developer machines and makes it easy for new team members and contributors to get up and running.
🌐
Reddit
reddit.com › r/docker › difference between vscode's "remote - containers" and docker's "dev environments"?
r/docker on Reddit: Difference between VSCode's "Remote - Containers" and Docker's "Dev Environments"?
April 10, 2021 -

I'm new to all this. I want to create a containerized environment for each language to stay organized and learn Docker/Linux. What is the difference between the Remote Containers extension and the Dev Environments feature of Docker? Are they both using the same underlying Docker features to create an environment? Are both required for my purposes? What's the best practice for an environment container I probably won't ever need to share with anyone? Thanks!

Top answer
1 of 4
11
VSCode's remote-containers lets you connect to containers, either containers set up on another machine or set up locally. It makes it much easier to set up the networking so that you don't have to configure all the ports. If you're learning Docker, VSCode makes it so much easier. It has a few quirks, especially if you're running it on Windows with Docker Desktop/WSL2, but if you pair it with the Docker VSCode extension, it becomes incredibly easy to learn.
2 of 4
3
What I don't like about remote containers is that they cannot be used along with remote SSH. I have a remote host with a monorepo including multiple development containers. I want to be able to connect to the Remote SSH, and optionally from there, connect to the Remote Container. Instead the best option is to set the DOCKER_MACHINE IP to the remote SSH socket and connect directly to it with VSC Remote Container. But that means my VSC environment is in an isolated development container in the monorepo, rather than the host machine. I've considered moving the whole dev environment into the container, since that's basically what I do already in CI where I need to use "docker in docker" (dind). Then I would connect directly to that development container instead of the remote host. This way I wouldn't need to setup launch configs and port forwarding for each container in order to get debugging to work. So I think it might be a good option, but problem is then I lose out on any host-only features of the remote environment. I suppose I could open ssh on the host for connections from docker, and then use DOCKER_HOST to connect to the host in an SSH session from the container when I need to.
🌐
Visual Studio Code
code.visualstudio.com › remote › advancedcontainers › overview
Advanced container configuration
November 3, 2021 - The Visual Studio Code Dev Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full ...
🌐
Visual Studio Code
code.visualstudio.com › docs › remote › ssh
Remote Development using SSH
November 3, 2021 - The Visual Studio Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code's feature set.
Find elsewhere
Top answer
1 of 11
28

I resolved this problem by switching to the remote server's Docker context on my local machine:

docker context create some-context-label --docker "host=ssh://user@remote_server_ip"

docker context use some-context-label

docker ps
# A list of remote containers on my local machine! It works!

After that:

  1. Connect via Remote-SSH to the container server
  2. Right click relevant container -> the "Attach Visual Studio Code"

That works for me.

(Note: One would think that I should be able to just use my local VSCode (skip step 1) to connect to said remote container after switching my local context, but VSCode complains Failed to connect. Is docker running? in the Docker control pane.)

2 of 11
8

This might sound very strange, but for me, I had to open a folder on the remote SSH server prior to using the Remote Containers extension in VS Code. If I didn't do that, then it would constantly try to find the docker service running locally, even though the terminal tab was connected to the remote SSH server.

This seems very weird, because if you're conncted via SSH in VS Code, then the extension should assume you're trying to attach to the container on the remote server. Shouldn't have to open a remote folder first.

By "opening a folder" on the remote server, the Remote Containers extension was then able to attach VS code to the container running on the remote SSH server. I didn't have to do any of the steps in any of those articles. Just simply use Remote SSH to connect VS Code remotely via SSH, open a folder, and then use Remote Containers.

🌐
Visual Studio Code
code.visualstudio.com › docs › remote › remote-overview
VS Code Remote Development
November 3, 2021 - Visual Studio Code Remote Development allows you to use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment.
🌐
Docker
docker.com › blog › how-to-develop-inside-a-container-using-visual-studio-code-remote-containers
How to Develop Inside a Container Using Visual Studio Code Remote Containers | Docker
June 16, 2020 - As with all the other VS Code extensions, you also manage this with the Command Palette. You can either use the shortcut or the green button in the bottom left corner to open it. In the popup, search for Remote-Containers and select Open Folder in Container…
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Visual Studio Code Remote Development Extension Pack
Extension for Visual Studio Code - An extension pack that lets you open any folder in a container, on a remote machine, or in WSL and take advantage of VS Code's full feature set.
🌐
GitHub
github.com › microsoft › vscode-remote-release
GitHub - microsoft/vscode-remote-release: Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set. · GitHub
Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set. - microsoft/vscode-remote-release
Starred by 4.1K users
Forked by 437 users
Languages   Dockerfile
🌐
GitHub
github.com › microsoft › vscode-dev-containers
GitHub - microsoft/vscode-dev-containers: NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own! · GitHub
November 30, 2023 - Visual Studio Code Dev Containers and GitHub Codespaces Open your code in the cloud, in a local container, on a remote machine, or in WSL and take advantage of VS Code's full feature set.
Starred by 4.7K users
Forked by 1.4K users
Languages   Shell 78.1% | Dockerfile 8.2% | JavaScript 7.0% | Jupyter Notebook 4.4% | Python 0.9% | C# 0.4%
🌐
Opengeosys
opengeosys.org › stable › docs › devguide › advanced › vscode-devcontainer
Develop with VS Code Remote – Containers
Visual Studio Code is a powerful text editor which can be expanded to a full featured integrated development environment (IDE) with plugins. With the Visual Studio Code Remote - Containers extension you can use prebuilt Docker container as the runtime environment for your code development.
🌐
Microsoft Learn
learn.microsoft.com › en-us › shows › tabs-vs-spaces › visual-studio-code-remote-dev-with-containers--codespaces
Visual Studio Code: Remote Development with Containers & Codespaces | Microsoft Learn
February 18, 2021 - In part 2 of Remote Development with Visual Studio Code, Brigit Murtaugh, a PM with VS Code, will explain how to set up a remote development environment using either Docker containers or GitHub Codespaces. Chapters [00:19] - What is remote development in VS Code?
🌐
Lei Mao's Log Book
leimao.github.io › blog › VS-Code-Development-Remote-Host-Docker
VS Code Development Using Docker Containers on Remote Host - Lei Mao's Log Book
June 6, 2020 - By default, the VS Code Remote-Container uses local Docker host. This means that we are actually running the containers on the local computer. To use the container running on the remote host server, we have to add "docker.host":"your-user-name-on-host@hostname" to VS Code settings.json.
🌐
Chris Meagher's blog
meeg.dev › blog › getting-started-with-vs-code-remote-containers-on-windows
Getting started with VS Code Remote Containers on Windows | Chris Meagher's blog
June 8, 2021 - VS Code's Remote Containers help to describe, setup and configure reproducible and portable development environments. This post talks a bit about my motivation for using them, how I got started, and what I think so far.
🌐
GitHub
github.com › microsoft › vscode-remote-try-go
GitHub - microsoft/vscode-remote-try-go: Go sample project for trying out Dev Containers · GitHub
You can connect to the server in the container by either: Clicking on Open in Browser in the notification telling you: Your service running on port 9000 is available. Clicking the globe icon in the 'Ports' view. The 'Ports' view gives you an organized table of your forwarded ports, and you can get there by clicking on the "1" in the status bar, which means your app has 1 forwarded port. Notice port 9000 in the 'Ports' view is labeled "Hello Remote World."
Starred by 340 users
Forked by 225 users
Languages   Go
🌐
Microsoft Learn
learn.microsoft.com › en-us › shows › beginners-series-to-dev-containers › installing-the-remote-containers-extension-2-of-8--beginners-series-to-dev-containers
Installing the Remote - Containers Extension [2 of 8] | Microsoft Learn
January 26, 2021 - Now that we know what it means to develop in a container and why you'd want to do container-based development, join Burke Holland to learn how to install the Remote - Containers extension in Visual Studio Code and see how it works.Learn more:Remote - Containers Microsoft Learn Module: https://aka.ms/devcontainers-learn-moduleRemote - Containers Extension on the marketplace: https://aka.ms/remote-containers-extensionMain Remote - Containers Documentation: https://aka.ms/vscode-remote-containersRemote - Containers Tutorial: https://aka.ms/vscode-remote-containers-tutorialWatch entire series: https://aka.ms/BeginnerSeriesToDevContainersFollow:https://twitter.com/brigitmurtaughhttps://twitter.com/burkeholland