I heard that you can develop in a remote environment using VScode, so I tried it.
[Local PC] ・ Windows 10 pro ・ VScode 1.50.1 ・ OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
[Remote destination environment] ・ Ubuntu 18.04 LTS (on GCP) ・ Docker 19.03.13 ・ Python3 series
** Set up for SSH connection to VM instance on GCP ** Refer to [SSH connection to GCP VM instance from local PC].
python
#Check if python3 system is installed
$ sudo python --version
$ sudo python3 --version
#If you don't have python3, do the following
$ sudo apt update
$ sudo apt install -y python3
$ sudo apt install -y python3-pip
Python package installation
python
$ pip3 install numpy pandas beautifulsoup4
#* The purpose of the python package is to check it later, so put in a package that is not on your local PC.
** Install docker ** [Systemctl cannot be used on Ubuntu in Docker container] Refer to step 1.
docker = ce = 5: 19.03.14 ~ 3-0 ~ ubuntu-bionic
** Prepare a key pair for SSH connection directly to the container environment ** Key generation is the same as the first step. * The same key as the host can be used, but this time it will be created separately.
** Create container **
python
$ sudo docker container run -it -d -p 20022:22 --name test_con python:3
#Enter the container and install the package
$ sudo docker container exec -it test_con /bin/bash
Commands in the container
apt update
apt install nano
#SSH key setting
apt install -y openssh-server
mkdir /var/run/sshd
mkdir /root/.ssh/
nano /root/.ssh/authorized_keys
#* Copy the contents of the public key
##python package installation
pip install numpy pandas peewee
#Start SSH server
/usr/sbin/sshd -D
Remote --SSH
.ssh/config
file on your local PCEdit the contents of the configuration file referring to the following.
.ssh/config
Host gcp
HostName [GCP external IP]
User [User name for SSH connection]
Port [Port number] * If not stated, it will be port 22.
IdentityFile [path to private key]
command prompt
> ssh gcp
#You will probably be asked to enter a passphrase.
python
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'C:\\Users\\Path to private key' are too open.
python
Permission denied, please try again.
A new window will open where you can quickly select Linux
in the target host's OS category.
Could not establish connection to ....
and you will not be able to connect.** Check if the remote environment is available from bash **
When connected for the first time, TERMINAL is 1.install
, so click" + "to add bash.
Check if you can use the remote environment properly
python
$ python3
>>> import numpy
>>> from bs4 imoprt BeautfulSoup
** OK if you can do it! ** **
.ssh/config
file on your local PCEdit the contents of the configuration file referring to the following.
.ssh/config
Host gcp
HostName [GCP external IP]
User [User name for SSH connection]
Port [Port number] * If not stated, it will be port 22.
IdentityFile [path to private key]
Host gcp_container
HostName [GCP external IP]
User [User name to connect to SSH] * Because no user was created in the container this time.[root]
Port [Port number] * Port number on the host side with port mapping (20022 in this case)
IdentityFile [Path to private key] * A key different from the above host
Make an SSH connection from VScode in the same way as ** Step 3 ** and check if the container environment is used properly. After the connection is completed, execute the following from TERMINAL.
python
$ python
>>> import pandas
>>> imoprt peewee
** OK if you can do it! ** **