Access the docker environment in the remote environment using VScode. (The image of the connection is as shown in the figure.) I have been developing with jupyter-lab without knowing this method, but it was very difficult to modify the py file and edit the web code. .. (It can be easily realized just by using docker context ...) It's a very useful method, so please give it a try!
If you find it helpful, I would appreciate it if you could use LGTM m (_ _) m
On the client side, enter the ssh connection conditions in the configuration file
~/.ssh/config
Host home-ubuntu
HostName home-ubuntu.mydns.jp
IdentityFile ~/.ssh/home_ubuntu
User shota
Port 5504
TCPKeepAlive yes
IdentitiesOnly yes
What is docker context? (Quoted from the document below)
A single Docker CLI can have multiple contexts. Each context contains endpoint and security information needed to manage different clusters and nodes. You can easily set and switch between those contexts with the docker context command. Once you've set the context, you can easily switch between contexts by simply running the top-level command docker context use
.
Create and switch the context from the following command
# 1.Add context
$ docker context create home-ubuntu --docker "host=ssh://shota@home-ubuntu"
# home-ubuntu
# Successfully created context "home-ubuntu"
# 2.Switching context
$ docker context use home-ubuntu
# home-ubuntu
# 3.Confirm context
$ docker context ls
# NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
# default moby Current DOCKER_HOST based configuration # unix:///var/run/docker.sock swarm
# home-ubuntu * moby
If you check the image and container with the docker command, you can see that it is switched to docker on the host side
$ docker ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 451ead9000bf tensorflow-from-scratch "/bin/bash" 2 hours ago Up 2 hours tensorflow-from-scratch
Install the following two extensions in VScode
If you click the extended icon of remote connection and click the window mark or folder mark, you can see the docker conteainer on the host side that you switched earlier. Successful access!
When returning the target to the docker to be used locally
$ docker ps
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# 451ead9000bf tensorflow-from-scratch "/bin/bash" 2 hours ago Up 2 hours tensorflow-from-scratch
#When returning the target
$docker context use default
$ docker ps -a
#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
#0b0edc2e9df2 conda-init-env "bash" 2 hours ago Exited (255) 44 minutes ago conda-init-env
#↑ Different container is displayed
that's all! If you find it helpful, I would appreciate it if you could use LGTM m (_ _) m