1.下载centos镜像
docker pull centos:7.9.2009
2.后台启动容器
docker run -d --name=centos7 --privileged centos:7.9.2009 /usr/sbin/init
3.进入centos7容器中
docker exec -it centos7 /bin/bash
4.安装ssh
yum install -y openssh-server
5.修改登录密码
passwd root
6.ssh设置
启动ssh服务:systemctl start sshd.service ssh开机启动:systemctl enable sshd.service 查看ssh状态:systemctl status sshd.service
7.commit提交为新的镜像
docker commit -m="passwd:root,add-ssh" -a="zgbo" 937e1c568a51 centos7.9.2009:1.0
8.以后使用这个新镜像就可以了
docker run -d --name=centos7 --privileged -p 5111:22 centos7.9.2009:1.0 /usr/sbin/init
![](/i/l/?n=22&i=blog/2833597/202210/2833597-20221011154814701-1307247417.png)
标签:centos,--,centos7,ssh,docker,2009,运行 From: https://www.cnblogs.com/dabo-tian/p/16779501.html