Using Remote Docker Containers in Visual Studio Code

Using Remote Docker Containers in Visual Studio Code

You need ssh access on remote server via authorized_keys

Setup SSH Access if Required

Get your public key

cat ~/.ssh/id_rsa.pub

Logon to your target server and install your public key

cat >> ~/.ssh/authorized_keys

Make sure authorized_keys has proper permission; otherwise it won't work

chmod 600 ~/.ssh/authorized_keys

Visual Studio Code Setup

Prerequisites

  • Docker machine installed on remote server
  • Visual Studio Code installed on local machine
  • Docker plug-in installed on Visual Studio Code
  • Remote - Containers plug-in installed on Visual Studio Code

You will need to create a Docker Context

Refer: https://stackoverflow.com/questions/60425053/vs-code-connect-a-docker-container-in-a-remote-server

Here's an example of one

docker context create macbook-parallels --docker "host=ssh://mruckman@192.168.86.34"

Now you need to use this context, any Docker command you run, will be against that remote server, once context is used

docker context use macbook-parallels

Now launch Visual Studio Code, you will see your remote container and images now. Launch your desired remote container, and you can now attach to it.

If you want to revert back to your local Docker context

docker context use default

Other helpful context commands

List all of your contexts

docker ls

Remove a context

docker rm context-to-remove

Leave a Reply