拉取centos镜像
D:\ docker_image\ docker_test> docker pull centos:centos7.9.2009
centos7.9.2009: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Status: Downloaded newer image for centos:centos7.9.2009
docker.io/library/centos:centos7.9.2009
运行镜像 (/usr/sbin/init可在docker里启动服务,privileged特权容器)
D:\ docker_image\ docker_test> docker run -itd --privileged= true -p 9996 :22 --name test centos:centos7.9.2009 /usr/sbin/init
4a68f395e624b371f299c3a1c826b0f407ca12a148fe799a458c459fb23441fd
进入镜像
D:\ docker_image\ docker_test> docker exec -it test bash
[ root@4a68f395e624 /]
进入docker后,使用passwd密码来修改密码
[ root@4a68f395e624 /]
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.
[ root@4a68f395e624 /]
docker中安装Openssh
yum -y install openssh-server openssh-clients
修改SSH配置文件以下选项
[ root@4a68f395e624 /]
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitRootLogin yes
启动ssh服务
[ root@4a68f395e624 /]
登录测试
ssh root@本机ip -p 9996