Managing your remote servers and docker containers from within VS Code


Are you in need to connect to remote servers and docker containers from within VS Code? If so, this guide will help you.

Prerequisites

Firstly install the Remote Development and Docker VS Code extensions. After that, open a terminal and create a new docker context for each of your remote servers: docker context create NAME --docker "host=ssh://USERNAME@IP:PORT"

Now, inside VS Code, click th “Remote Explorer” extension and select the “Dev Containers” dropdown. You should see all your running containers of the current docker context. Connect to any of the running containers by clicking the “arrow” or “new window” icon. To switch docker context, simply run docker context ls to show all your available docker contexts followed by docker context use NAME.

Yo can manage and switch your docker contexts via the “Docker” extension by simply clicking on it an opening the “Contexts” panel. The “Docker” extension is also a great place to get an overview of the current docker context with all the provided panels for Containers, Images, Registries, Networks and Volumes from within VS Code.

You can also use the “Remote Explorer” to connect to any added server via SSH (Remote (Tunnels/SSH) dropdown) and work remotely.

With that, you will never have to leave the comfort of your VS Code Instance to do wok on remote systems.

Further reading: