zoukankan      html  css  js  c++  java
  • Docker-为镜像添加SSH服务(CentOS)

    Dockerfile方式创建镜像并启动容器

      https://www.cnblogs.com/BINGJJFLY/p/12808549.html

      可以添加root密码:echo root:root | chpasswd

    安装配置SSH服务  

    yum install openssh-server openssh-clients -y
    vim /etc/ssh/sshd_config
    #HostKey /etc/ssh/ssh_host_ecdsa_key
    #HostKey /etc/ssh/ssh_host_ed25519_key
    

    创建公私钥

    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    ls /etc/ssh/
    

    修改root密码 

    echo root:root | chpasswd
    

    启动SSH服务

    /usr/sbin/sshd -D &
    netstat -tunlp

    Commit方式创建镜像  

    docker commit -m="create an sshd image" -a="bingjjfly" 容器的ID REPOSITORY:TAG
    

    创建拥有SSH服务的容器

    # 可以映射不同的端口
    docker run -p 1022:22 -d SSH镜像ID
    

    Dockerfile方式创建镜像

    FROM centos:centos6.8
    MAINTAINER bingjjfly<bingjjfly@docker.org>
    RUN yum install openssh-server openssh-clients -y
    RUN mkdir /var/run/sshd
    RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
    RUN /bin/echo 'root:root'|chpasswd
    RUN /bin/sed -i 's/.*session.*required.*pam_loginuid.so.*/session optional pam_loginuid.so/g' /etc/pam.d/sshd
    RUN /bin/echo -e "LANG="en_US.UTF-8"" > /etc/default/local
    EXPOSE 22
    CMD /usr/sbin/sshd -D
    
    docker build -f /mydocker/ssh/Dockerfile -t bingjjfly/ssh:1.0 .
    
    docker run -d -p 1022:22 --name bingjjfly_ssh_1.0 bingjjfly/ssh:1.0
    

    SSH方式连接服务器

    # 宿主机IP
    ssh root@192.168.88.128 -p 1022  

       

  • 相关阅读:
    tar (child): gzip: Cannot exec: No such file or directory
    通过应用数字格式来修复文本格式的数字
    Logback
    Transport
    nginx note
    docker note
    k8s note
    spring boot properties
    Windows 和 Linux 的文件名
    安装配置ubuntu的web项目(新)
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/12835468.html
Copyright © 2011-2022 走看看