1.拉取centos镜像
docker pull centos:7
2.进入初始化centos系统
docker run -tdi --privileged 镜像名 init
3.进入容器 配置ssh
> docker ps -a
> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS AMES
0d77d1bf15b3 centos "init" 8 seconds ago Up 8 seconds elegant_joliot
> docker exec -it 0d bash
> su root
> passwd
Changing password for user root.
New password: 你的密码
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
Retype new password: 你的密码
passwd: all authentication tokens updated successfully.
> yum install openssh-server -y
> vi /etc/ssh/sshd_config
修改/etc/ssh/sshd_config配置并保存:
PermitRootLogin yes
UsePAM no
> systemctl start sshd
> exit
4.构建并启动镜像
#构建镜像
> docker commit --author "gyu" --message "容器centos开启远程ssh成功" CONTAINER ID gyu/centos7
# 启动镜像
> docker run -d -p 40000:22 --name gyu-centos --privileged=true gyu/centos7 /usr/sbin/init