[DOCKER] How to develop containers on remote servers with VS Code Remote-Containers

Overview

--Run Remote-Containers in VS Code on your local terminal to connect directly to a container on a remote server for development --The container does not start on the local terminal --Ssh connection to the remote server automatically when Remote-Containers is executed --No separate SSH connection required --Connect to the container port using Forward Port / Publish Port --You can test the operation with the browser of the local terminal.

environment

--Local device: MacBook Pro (macOS Catalina)

Background

I encountered a bug in Docker Desktop for Mac while trying to set up a development environment for VS Code + Remote-Containers on Mac.

--Docker does not start on Docker Desktop for Mac stable version (2.1.0.5) on macOS Catalina --Docker starts in Edge version (2.1.7.0), but the process of com.docker.hyperkit sticks with 100% CPU (fans make a roar)

Looking at the issue on GitHub, Docker does not start and the process runaway bug has continued for a long time and no improvement can be expected in the future.

There is also a process runaway bug in the VS Code documentation.

After some trial and error, I decided to stop running Docker on a Mac, run Docker on a Linux server, and seek an environment to connect remotely to it. However, the default setting of Remote-Containers starts the container in the local Docker environment, so I searched for a way to connect to the remote server and realized it.

How to connect to a remote server with Remote-Containers

The explanation about the introduction and setting of VS Code and Extensions is omitted.

Target document

It is described under the title Developing inside a container on a remote Docker host.

Setting method

It's easy to set up, just add the docker.host line to setting.json and restart VS Code.

** Setting example of setting.json **

    "docker.host": "ssh://[email protected]"

Key authentication is required for SSH connection to the remote server, so set it.

Click here for documentation on SSH settings in VS Code.

Once the keys are ready on both the server and client, configure the settings for VS Code.

In VS Code, run Remote-SSH: Open Configuration File... in the Command Palette (F1), select the SSH config file you wish to change, and add (or modify) a host entry in the config file as follows to point to the file:

Actually, it is an SSH config setting, so it seems that there is no problem even if you change it directly. Specify the key location by adding the line ʻIdentityFile`.

** ~ / .ssh / config setting example **

Host 192.168.1.60
  HostName 192.168.1.60
  User root
  IdentityFile ~/.ssh/id_rsa

You can now connect directly to the container on the remote server with Remote-Containers. There seems to be a method using TCP protocol other than SSH protocol, but it has not been verified.

Forward Port Immediately after starting Remote-Containers, the local terminal and the container on the remote server are isolated, so you cannot connect directly to the port inside the container. Therefore, add Forward Port to forward the port of the local terminal to the port in the container.

Target document

procedure

  1. Start the server you want to test in the container and check that the port is listening.
  2. Select F1 → Remote-Containers: Forward Port from Container ....
  3. Select Forward XXXX (XXXX is the port number started in the container)
  4. Connect to http: // localhost: XXXX with the browser of the local terminal or curl command (If you specify localhost in Safari on Mac, an error will occur, so you can connect by replacing it with 127.0.0.1)

Publish Port If it is troublesome to set the Forward Port every time the container is started, set the Publish Port and set the port forwarding to always be done when the container is started.

Target document

procedure

  1. Add the setting of ʻaddPort to devcontainer.json` and specify the port.
  2. Select F1 → Remote-Containers: Rebuild Container. Rebuild the container.
  3. Start the server you want to test in the container and check that the port is listening.
  4. Connect to http: // remote server IP or FQDN: XXXX with a local terminal browser or curl command

** Setting example of devcontainer.json (docker: 9000, container: 5000) **

	"appPort": ["9000:5000"],

If you execute docker ps in the above example, the PORTS of the target container ID will be 0.0.0.0:9000-> 5000 / tcp.

Summary

I was able to set up a seamless container development environment with VS Code. You only need to prepare VS Code on your local terminal, and you don't even need Docker. It is a condition that the remote server is started and a network connection is always required, but I think that a stress-free development environment has been built to the extent that enough change comes. Please refer to the container development using Remote-Containers.

Recommended Posts

How to develop containers on remote servers with VS Code Remote-Containers
Get the strongest environment with VS Code, Remote-Containers and remote docker-daemon
How to build Python and Jupyter execution environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
How to use VS Code (code server) with Google Colab in just 3 lines
Strategy on how to monetize with Python Java
How to develop a cart app with Django
How to install OpenGM on OSX with macports
Steps to attach and debug from VS Code to Jupyter Lab on a remote server
How to make a Python package using VS Code
Autoencoder with Chainer (Notes on how to use + trainer)
[Django] Use VS Code + Remote Containers to quickly build a Django container (Docker) development environment.
Remote debug Django environment created with docker-compose with VS Code
How to operate Firefox with selenium on Windows Memo
[No venv required] The strongest Python development environment created with Remote Containers [VS Code / Docker]
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
Try Fortran with VS Code up to debug settings. [Win10]
Build a Go development environment with VS Code's Remote Containers
[Ev3dev] How to display bmp image on LCD with python
Settings to debug the contents of the library with VS Code
How to install Theano on Mac OS X with homebrew
Try HeloWorld in your own language (with How to & code)
Python with VS Code (Windows 10)
How to register on pypi
How to update with SQLAlchemy?
Debug Python with VS Code
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to develop in Python
How to Delete with SQLAlchemy?
How to write code to access python dashDB on Bluemix or local
How to customize U-Boot with OSD335X on a custom board (memo)
How to run Jupyter and Spark on Mac with minimal settings
How to use python put in pyenv on macOS with PyCall
Getting started on how to solve linear programming problems with PuLP
How to connect to Cloud Firestore from Google Cloud Functions with python code
How to get all traffic through VPN with OpenVPN on Linux
Edit files directly on Linux with Visual Studio Code Remote SSH
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
Steps to develop Django with VSCode
Python: How to use async with
How to install mysql-connector-python on mac
Notes on how to use pywinauto
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to install graph-tool on macOS
How to deal with imbalanced data
How to install VMware-Tools on Linux
How to install pycrypto on Windows
How to deploy django-compressor on Windows
Notes on how to use featuretools
How to install OpenCV on Mac
How to run matplotlib on heroku
How to install PyPy on CentOS
How to get started with Scrapy
How to get started with Python
How to use homebrew on Debian