本文共 1606 字,大约阅读时间需要 5 分钟。
在开始操作之前,请确保已安装好PyCharm专业版,社区版不支持远程服务器连接。以下是通过SSH连接已运行的Docker容器的详细步骤:
根据你的Docker版本选择相应的运行命令:
Docker版本19.03及以上:
docker run -itd --shm-size=8G -entrypoint="" -p 8089:22 --name="pgf_train" --gpus all -v /home/th/PycharmProjects/qa/:/workspace/qa pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime /bin/bash
-p 8089:22:将主机端口8089映射到容器内的22端口。--gpus all:将所有可用的GPU分配给容器。--shm-size=8G:为容器分配8GB的共享内存,提升性能。Docker版本19.03以下:
docker run -itd --shm-size=8G -entrypoint="" -p 8089:22 --name="pycharm_train2" -e NVIDIA_VISIBLE_DEVICES=2,3 -v /mnt/inspurfs/user-fs/panguofeng:/pgf_api pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime /bin/bash
NVIDIA_VISIBLE_DEVICES=2,3:指定使用GPU2和GPU3。在运行完成后,通过SSH方式登录容器:
ssh root@127.0.0.1 -p 8089
进入容器后,执行以下命令修改root密码:
passwd
安装OpenSSH Server和Client:
apt-get install openssh-server openssh-client
在安装完成后,更新源并重新启动SSH服务:
apt-get -y update/etc/init.d/ssh restart
编辑sshd_config文件,添加以下内容:
vim /etc/ssh/sshd_config
在文件末尾添加:
PermitRootLogin yes
/etc/init.d/ssh restart
ssh root@127.0.0.1 -p 8089
输入刚修改的root密码,成功登录后即可进入容器。
在PyCharm中,依次完成以下步骤:
Ctrl + Alt + S)。将本地代码文件传输到容器:
设置Python解释器:
/usr/local/...)。运行代码:
注意:请确保容器内已安装必要的Python库和PyTorch环境,例如通过pip安装所需的依赖。
转载地址:http://xkafk.baihongyu.com/