Xshell连接docker centos 7

# 1、下载运行centos:7
docker run -tdi --name test-centos --privileged centos:7 init
# 2、进入刚刚运行的容器
docker exec -it test-centos bash
# 3、在容器中执行passwd设置登录密码为123456
passwd
# 4、
在容器中安装容器的openssh-server
yum install openssh-server -y
修改/etc/ssh/sshd_config配置并保存:38行 PermitRootLogin yes  96行  UsePAM no

# 5、启动ssh服务 ,启动成功后退出容器
systemctl start sshd
exit
# 6、将设置好命令的启动状态的容器构建为新的镜像
docker commit  --author "test"  --message "容器centos开启远程ssh"  test-centos  test/centos7-ssh:1.0.0
# 7、运行新的镜像并配置端口映射,左边的22代码对外的端口号,右面的22代表容器本身的端口号
docker run -d --name=centos7-ssh-test -p 22:22 test/centos7-ssh:1.0.0 /usr/sbin/sshd -D
# 8、打开Xshell或者其他ssh工具,连接你的容器

# 9、Dockerfile构建
FROM centos:7
RUN yum install openssh-server -y \
    && echo "123456" |passwd --stdin root \
    && sed -i '38cPermitRootLogin yes' /etc/ssh/sshd_config
CMD ["usr/sbin/init"]

  docker build -t test/centos7-ssh:1.0.1 .

  docker run -d --name=centos7-ssh-test-df -p 24:22 test/centos7-ssh:1.0.1 

 
 
posted @ 2021-02-18 15:45  已老  阅读(539)  评论(0编辑  收藏  举报