xshell连接windows10中的docker
先安装centos,不选版本,默认最新版
[C:\~]$ docker pull centos
查看安装的镜像
-
[C:\~]$ docker images
-
REPOSITORY TAG IMAGE ID CREATED SIZE
-
morton/ubuntu dev f2657d57c189 3 months ago 137MB
-
morton/ubuntu v2 f2657d57c189 3 months ago 137MB
-
docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
-
mortonshaw/docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
-
ubuntu latest bb0eaf4eee00 3 months ago 72.9MB
-
node 12-alpine 1f52b7199ba6 3 months ago 89.3MB
-
python alpine 0f03316d4a27 3 months ago 42.7MB
-
nginx alpine 6f715d38cfe0 4 months ago 22.1MB
-
centos latest 0d120b6ccaa8 4 months ago 215MB
-
centos centos7.2.1511 9aec5c5fe4ba 21 months ago 195MB
-
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
-
training/webapp latest 6fae60ef3446 5 years ago 349MB
启动镜像
说明
- -p 端口映射
- --name 指定容器名称
- --privileged=true 打开权限
- /usr/sbin/init 启动systemd服务
其中后两项是必须的,否则不能使用systemctl管理ssh服务
[C:\~]$ docker run -itd -p 50001:22 --name centos_ssl --privileged=true centos /usr/sbin/init
查看容器
-
[C:\~]$ docker ps -a
-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-
790d0ff9e176 centos "/usr/sbin/init" 3 minutes ago Up 3 minutes 0.0.0.0:50001->22/tcp centos_ssl
-
00de92573eac centos:centos7.2.1511 "/bin/bash" 3 months ago Exited (137) 2 months ago centos-zabbix
进入容器
[C:\~]$ docker exec -it centos_ssl /bin/bash
安装SSH相关服务
[root@36157c757262 /]# yum install -y openssh*
启动服务
-
[root@36157c757262 /]# systemctl start sshd
-
[root@36157c757262 /]# systemctl enable sshd
-
[root@36157c757262 /]# systemctl status sshd
初始化root用户密码,密码为root
-
[root@36157c757262 /]# yum install -y passwd
-
[root@36157c757262 /]# passwd root
-
Changing password for user root.
-
New password:
-
BAD PASSWORD: The password is shorter than 8 characters
-
Retype new password:
-
passwd: all authentication tokens updated successfully.
xshell连接
和正常连接centos一样,ip写localhost(或本机ip),端口为50001(映射docker中的22端口)
docker容器停止/启动/删除等相关操作
-
[C:\~]$ docker stop centos_ssl
-
[C:\~]$ docker start centos_ssl
-
[C:\~]$ docker rm -f centos_ssl
分类:
Docker
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
2020-07-07 阿里面试Redis最常问的三个问题:缓存雪崩、击穿、穿透(带答案)