docker新建centos镜像并配置远程访问

1.# docker search centos 查找官方镜像

 

 

2.# docker pull centos 下载镜像(默认版本是latest)

3.# docker run -idt centos /bin/bash 启动镜像

4.# docker ps | grep centos 查看镜像id

 

5.# docker exec -it  0400b38b215a /bin/bash 进入容器

6.安装centos基础环境

  1)# yum -y install net-tools.x86_64 安装网络环境,完成后使用ifconfig查看ip等信息

  2)# yum -y install openssh-server 安装sshd,若出现:

    Could not load host key: /etc/ssh/ssh_host_rsa_key

    Could not load host key: /etc/ssh/ssh_host_ecdsa_key

    Could not load host key: /etc/ssh/ssh_host_ed25519_key

    解决方案:

    # ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
    # ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ""
    # ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""

  3)# vim /etc/ssh/sshd_config 编辑sshd_config配置文件 ,设置UsePAM为no

  4)# passwd 修改root默认密码;若提示没有这个命令,通过# yum -y install passwd安装

  5)# exit 命令退出到host主机

7.# 打包新镜像:docker commit -m "提交信息" 镜像id 新镜像名称

8.# 启动新镜像:docker run -itd -p 50001:22 新镜像名称 /user/sbin/sshd -D

9:远程连接:ssh root@localhost -p 50001

 

posted @ 2020-06-14 14:57  Katsu  阅读(912)  评论(0编辑  收藏  举报