1、拉取centos7镜像docker pull centos:centos7
2、运行docker 镜像
3、进入centos容器
4、安装sshyum -y install openssh-server
5、启动ssh服务systemctl start sshd
6、修改/etc/ssh/sshd_config 配置信息去掉如下注释Port 22ListenAddress 0.0.0.0ListenAddress ::permitrootlogin yesUsePAM yes 改为 UsePAM noGSSAPICleanupCredentials no改为GSSAPICleanupCredentials yes去掉UsePrivilegeSeparation sandbox的注释并改为UsePrivilegeSeparation no
7、重启sshd/usr/sbin/sshd -D
8、设置linux容器的密码passwd root
9、提交镜像
10、运行新镜像
11、使用ssh连接centos容器ssh root@宿主机的ip -p 10022