docker articles --- pycharm connects docker, using docker environment

1. Generate images and containers

Refer to my other blog

You can also pull the corresponding image according to your own needs
insert image description here

1.1 To create a container, you need to add port mapping

docker run --name py_gpu --runtime=nvidia -it -p 2222:22 cuda-11.3-pytorch:v1 /bin/bash

insert image description here

1.2 Entering the container

root@67a90f086ded:/# apt-get update
root@67a90f086ded:/# apt-get upgrade
root@67a90f086ded:/# apt-get install vim
root@67a90f086ded:/# apt-get install openssh-server

At this point, all the preparatory work is completed, and the actual operation of connecting ssh begins

1.3 Set the root password, which will be used for subsequent logins

root@67a90f086ded:/# passwd 

set up123456

1.4 Modify the configuration file

root@67a90f086ded:/# vim /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes

UsePAM no # 原先为 yes

Comment this line PermitRootLogin prohibit-password
Add a line PermitRootLogin yes
UsePAM yes change to no #Disable PAM

1.5 Restart the ssh service

root@67a90f086ded:/# service ssh restart 
 * Restarting OpenBSD Secure Shell server sshd 

insert image description here

1.5 local connection ssh

ssh root@127.0.0.1 -p 2222

insert image description hereconnection succeeded!

Two, pycharm connect docker

2.1 Allow remote client connections

Modify docker to allow remote client connections

Modify the configuration file

vim /lib/systemd/system/docker.service

Find the line where ExecStart is located

# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock

insert image description here 
Important: In order to be able to use this Docker socket, you need to have appropriate permissions at the process level (docker.pid) and file level (docker.sock). So executing the following two commands should solve your problem
 

sudo chmod a+rwx /var/run/docker.sock
sudo chmod a+rwx /var/run/docker.pid

Save and exit, restart docker

sudo systemctl daemon-reload 
sudo systemctl restart docker

verify

# 内部能访问到:
curl 127.0.0.1:2376/version
# 外部访问不到(防火墙,入网规则)
# ubutun 关闭防火墙: sudo ufw disable
systemctl stop firewalld.service
# 再次查看 
systemctl status firewalld.service  #关闭了

2.2 pycharm configuration docker

file----Settings
insert image description hereinsert image description here

Guess you like

Origin blog.csdn.net/m0_46825740/article/details/128829032