docker先启动centos
1.创建并启动centos容器:
docker run -tid --privileged --name centos_one -p 60001:22 -p 60002:80 -p 60003:3306 -v /var/centos_one/html/:/var/centos_one/html/ 5182e96772bf /usr/sbin/init
进入容器:
docker
exec
-it centos_one
/bin/bash
到这里我们已经进入了centos容器,在容器中安装ssh以及各种依赖:
yum install passwd openssl openssh-server openssh-clients -y
启动sshd服务:
systemctl start sshd.service
查看sshd状态如下图所示,已经启动成功了
systemctl status sshd.service
设置root密码:
passwd
root
说明连接成功