【六袆 - Linux】windos环境中的Docker,使用xshell连接docker容器中的ubuntu18.04;ssh登录docker容器ubuntu18.04

windos环境中的Docker,使用xshell连接docker容器中的ubuntu18.04;







就是这么自信💜

在这里插入图片描述

Ubuntu18.04 安装ssh
#换源:1.备份;
mv /etc/apt/sources.list /etc/apt/sourses.list.backup

#2.新建
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

#更新源
sudo apt-get update
sudo apt-get upgrade

输入service ssh status 查看ssh状态

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-notbBGe7-1625935989651)(F:\采集\Note\csdn我觉得写一篇笔记,对得住今天的学习\Untitled.assets\image-20210710234332349.png)]


启动ssh服务

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0DOv6ENn-1625935989654)(F:\采集\Note\csdn我觉得写一篇笔记,对得住今天的学习\Untitled.assets\image-20210710234539064.png)]


实现远程登录的配置
#编辑
vim /etc/ssh/sshd_config

#修改配置
1.将PermitRootLogin的值从withoutPassword改为yes  - 允许root登陆
2.将UseDNS yes 改为 UseDNS no - 开始我这个没改,xshell一直报错To escape to local shell, press 'Ctrl+Alt+]'

快速定位,输入指令:/PermitRoot 或者 UseDNS

#重启ssh服务
service ssh start


保存容器
#container_id 容器id ,response/tag 任意名称
docker commit container_id response/tag

在这里插入图片描述


重新运行容器
# 将docker的60001端口和container的22端口绑定,这样访问docker的60001等价于访问container的22端口
docker run -it -p 60001:22 xiaolh/ubuntu-v1 /bin/bash 

ssh连接container
#最容易出错的,Docker ip地址 如图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vuYJM5ao-1625935989659)(F:\采集\Note\csdn我觉得写一篇笔记,对得住今天的学习\Untitled.assets\image-20210711002703754.png)]

恭喜你,又完成了一个亿的小目标~

在这里插入图片描述

posted @ 2022-04-26 00:53  你好,Alf  阅读(114)  评论(0编辑  收藏  举报