1. Docker SSH configuration

1.1 After pulling a mirror, run the following command:

Sudo docker run --runtime=nvidia -- it -p 8023:22 --ipc=host --name="torch" -v /home/**:/home/** torch1.5/bin/bashCopy the code

Among them,

-p 8023:22: Sets the port mapping and forwards the tcp22 port to 8023 (the container will be accessed through the 8023 port). You can set the port mapping freely if it does not conflict with the occupied port.

–ipc=host: used to set shared memory between host and container;

-v /home/**:/home/** : shares the server directory with the container directory. The two directories are usually named the same for easy memory.

Torch1.5: name of the pulled mirror.

1.2 Starting and Entering containers:

sudo docker start torch
sudo docker attach torch
Copy the code

1.3 Setting the Password of User root

Passwd root * Password * * Enter the password again *Copy the code

Install openssh 1.4:

apt update
apt install -y openssh-server
Copy the code

1.5 SSH Configuration:

vim /etc/ssh/sshd_config
Copy the code

Modify the SSH configuration file to remove the # comment for the following options (if you cannot find the corresponding option, you can directly copy it to the file) :

Port 22 # Enable Port 22 PermitRootLogin yes # Allow root user to log in using SSH RSAAuthentication yes # Enable RSA authentication PubkeyAuthentication yes SSH/authorized_keys. SSH /authorized_keys2 # Path to the public key fileCopy the code

1.6 Restart the SSH service after the MODIFICATION is complete.

service ssh restart
Copy the code

1.7 Verifying port Mapping:

sudo docker port [ID] 22
Copy the code

If the following output is displayed, the configuration is successful

**@master:~$ sudo docker port torch 22
0.0.0.0:8023
Copy the code

2. VS p-code configuration

2.1 Installing Remote Development

Open VS Code and open the extension (CTR + Shift +X) to find and install Remote Development

2.2 Open the search bar (CTR + Shift + P), enter remote-ssh, and select Open Configuration File

2.3 Basic Configuration

2.4 Open Remote Explorer and select the configured host for SSH connection

2.5 Entering the Password of user root:

Connection successful:

3. Configure the VScode debugger

3.1 

Open the extension (Ctrl + Shift + X), search for “Python” in the store, select “Python extension for Visual Studio Code” and install it in the target container, then restart VSCode.

3.2

Press Ctrl + Shift + P, type “Python: Select Interpreter”, and click the Desired Python parser.

3.3 

Open the container directory to debug the code

References:

Python basics – VScode + docker for code debugging

VSCode+Docker: Create the most comfortable deep learning environment

VSCode Remote experience | Remote Linux environment development is really sweet

SSH connects to Containers in Docker

Docker-SSH connects to the Docker container