pycharm connects docker container remotely

1. Create a container based on the image

sudo docker run -itd --name=conn_test --runtime=nvidia --gpus all  -p 8089:22 test:v1 

2. Enter the container

sudo docker exec -it f08beeff759a /bin/bash

3. Modify the root password of the container

passwd 

Screenshot 2023-08-21 090841.png

4. Install openssh-server and openssh-client in the container

# apt-get -y update 如果下面命令报错,先执行这个命令,再重新执行下面的命令
apt-get install openssh-server
apt-get install openssh-client

5. Modify the SSH configuration file

  • edit file
    vim /etc/ssh/sshd_config
    
  • add content
    PermitRootLogin yes # 允许root用户使用ssh登录
    
    Screenshot 2023-08-21 091100.png

6. Restart the ssh service

/etc/init.d/ssh restart

7. Exit test

ssh [email protected] -p 8089

8. Configure pycharm and connect docker container

  • step one
    Screenshot 2023-08-18 103721.png

  • step two
    insert image description here

  • step three
    insert image description here

9. Select the docker environment

  • Configuration Environment
    insert image description here
  • test, run the file
    • View interpreter path is not local, successinsert image description here

Guess you like

Origin blog.csdn.net/m0_46926492/article/details/132401316