--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.
--Local device: MacBook Pro (macOS Catalina)
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 (220.127.116.11) on macOS Catalina
--Docker starts in Edge version (18.104.22.168), 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.
The explanation about the introduction and setting of VS Code and Extensions is omitted.
It is described under the title
Developing inside a container on a remote Docker host.
It's easy to set up, just add the
docker.host line to
setting.json and restart VS Code.
** Setting example of
"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.
Remote-Containers: Forward Port from Container ....
Forward XXXX(XXXX is the port number started in the container)
http: // localhost: XXXXwith 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.
todevcontainer.json` and specify the port.
Remote-Containers: Rebuild Container. Rebuild the container.
http: // remote server IP or FQDN: XXXXwith a local terminal browser or curl command
** Setting example of
devcontainer.json (docker: 9000, container: 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.
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.