(1).拉取镜像,镜像id:5e35e350aded?
docker?pull?centos:7
(2).运行镜像生成容器,容器id:44597c6694a3
docker?run?-d?-i?-t?-p?80:80?-p?21:21?-p?22:22?-p?23:23?-p?3306:3306?-p?6379:6379?-p?8888:8888?-p?9501:9501?-p?9502:9502?-v??/d/wwwroot:/www?--privileged??5e35e350aded?/usr/sbin/init
(3).进入容器:
docker?exec?-it?44597c6694a3?/bin/bash
(4).容器中安装ssh
yum?install?-y?openssh-server?openssh-clients
(5).vi /etc/ssh/sshd_config开启允许root登录,取消前面的注释#
PermitRootLogin?yes
(6).重启sshd服务
systemctl?restart??sshd
(7).上一步如果报错可执行(我的没有报错)
?ssh-keygen?-t?rsa?-f?/etc/ssh/ssh_host_rsa_key
?ssh-keygen?-t?ecdsa?-f?/etc/ssh/ssh_host_ecdsa_key
?ssh-keygen?-t?ed25519?-f?/etc/ssh/ssh_host_ed25519_key
(8).设置root密码
passwd
(9).测试ssh连接
?ssh?-p22?root@localhost
(10).注意点:--privileged和/usr/sbin/init是允许你开启特权运行,否则无法执行systemctl
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。