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状态
启动ssh服务
实现远程登录的配置
#编辑
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地址 如图
恭喜你,又完成了一个亿的小目标~