本地windows vscode远程连接服务器docker容器

本地windows vscode远程连接服务器docker容器

一、查看服务器中已有docker镜像:

(base) [root@os-compute-and-train-01]$ docker images
REPOSITORY        TAG                         IMAGE ID       CREATED         SIZE
solo       			latest                      aa0c0c99a87d   4 days ago      7.88GB
nvidia/cuda       9.0-base                    0bedd0dfd4cb   16 months ago   152MB
pytorch/pytorch   1.3-cuda10.1-cudnn7-devel   fe0f6ec79dbf   3 years ago     7.72GB

二、构建新的docker镜像:

(base) [root@os-compute-and-train-01]$ docker build . -t pytorch/pytorch:1.3-cuda10.1-cudnn7-devel-solo
Sending build context to Docker daemon  3.072kB
Step 1/12 : ARG PYTORCH="1.3"
Step 2/12 : ARG CUDA="10.1"
Step 3/12 : ARG CUDNN="7"
Step 4/12 : FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
 ---> fe0f6ec79dbf
Step 5/12 : ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
 ---> Using cache
 ---> 1b23d1bcc112

三、启动容器:

(base) [root@os-compute-and-train-01]$ docker run --name solo_container -it --shm-size 8G -v /home/hongxinxin/Project/实例分割/SOLO-master/:/SOLO/  -p 10086:22 --gpus all pytorch/pytorch:1.3-cuda10.1-cudnn7-devel-solo bash

四、docker容器内配置

1、进入容器中,使用如下命令修改root用户密码
root@d85e9b209bf3:~# passwd
2、安装ssh
root@d85e9b209bf3:~# apt install ssh
3、修改ssh配置文件
root@d85e9b209bf3:~# vim /etc/ssh/sshd_config  
# 将PermitRootLogin 设置为yes  #允许root用户使用ssh登录
4、启动sshd服务
root@d85e9b209bf3:~# /etc/init.d/ssh restart 

五、本地命令远程连接服务器docker容器

co@Uniml-Dev-Ai01 MINGW64 /
$ ssh root@192.168.60.101 -p 10086
The authenticity of host '[192.168.60.101]:10086 ([192.168.60.101]:10086)' can't be established.
ED25519 key fingerprint is SHA256:EAYiOQEC0tMRxBaKX5kvrguIUB3TMZVqbLpwmRNPOa0.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[192.168.60.101]:10086' (ED25519) to the list of known hosts.
root@192.168.60.101's password:
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 5.4.210-1.el7.elrepo.x86_64 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@d85e9b209bf3:~#

如果连接时出现以下错误:

co@Uniml-Dev-Ai01 MINGW64 /
$ ssh root@192.168.60.101 -p 10086
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:EAYiOQEC0tMRxBaKX5kvrguIUB3TMZVqbLpwmRNPOa0.
Please contact your system administrator.
Add correct host key in /c/Users/co/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/co/.ssh/known_hosts:15
Host key for [192.168.60.101]:10086 has changed and you have requested strict checking.
Host key verification failed.

去除C:\Users\co.ssh\config文件中关于服务器映射端口(这边端口时10086)
以上操作可以通过命令远程连接到docker容器。

六、vscode相关配置

1、vscode中安装remote ssh和dev containers插件

在这里插入图片描述

2、配置vscode的config文件

在这里插入图片描述填写config文件内容,按照以下格式:
在这里插入图片描述
特别注意:由于需要远程连接的是服务器上的docker容器,而且前面提到:ssh服务器的22号端口已经映射为10086,因此,务必增加一个Port,填写自己映射的端口。如果只是远程服务器,不需要用docker容器,则不需要增加Port这一行。配置完成后,保存配置。

3、开启远程连接

在这里插入图片描述此处输入之前容器设置的root密码进行连接:
在这里插入图片描述连接完成
在这里插入图片描述选择打开文件夹,就可进行项目开发:
在这里插入图片描述左上角框显示容器中所处项目目录,右下角框是容器的运行环境。

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值