美文网首页Amazing Arch
Docker技术入门与实战(带SSH的镜像)

Docker技术入门与实战(带SSH的镜像)

作者: SkTj | 来源:发表于2019-02-13 10:15 被阅读62次

    1、镜像制作
    yum install -y openssh-server
    mkdir -p /var/run/sshd
    sed -ri "s/session required pam_loginuid.so/#session required pam_loginuid.so/g" /etc/pam.d/sshd
    mkdir /root/.ssh
    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
    cat /root/.ssh/id_rsa.pub>/root/.ssh/authorized_keys
    ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key
    /usr/sbin/sshd -D &
    vi /root/run.sh

    !/bin/bash

    /usr/sbin/sshd -D

    chmod +x /root/run.sh
    echo "123456"|passwd --stdin root
    2、保存镜像
    docker commit centos7 hat/centos7ssh
    3、启动
    docker run -it -p 10022:22 --name "centos7" -d hat/centos7ssh /root/run.sh

    批量删除容器 docker rm docker ps -a -q

    4、连接方式
    ssh ip -p 10022
    5、上传镜像到阿里云
    https://cr.console.aliyun.com/repository/cn-shenzhen/hatdocker/centos7ssh/detail
    docker login --username=hatqiang registry.cn-shenzhen.aliyuncs.com
    docker tag 9e99ee67033f registry.cn-shenzhen.aliyuncs.com/hatdocker/centos7ssh:latest
    docker push registry.cn-shenzhen.aliyuncs.com/hatdocker/centos7ssh:latest
    //拉取
    docker pull registry.cn-shenzhen.aliyuncs.com/hatdocker/centos7ssh:latest
    //////////////////////////////////////////////////////////////////////////////
    Dockerfile文件方式
    mkdir centos7ssh
    cd centos7ssh
    touch Dockerfile run.sh
    vi run.sh

    !/bin/bash

    /usr/sbin/sshd -D

    vi Dockerfile
    FROM centos
    MAINTAINER hat
    RUN yum install -y openssh-server
    RUN mkdir -p /var/run/sshd
    ADD authorized_keys /root/.ssh/authorized_keys
    ADD run.sh /root/run.sh
    EXPOSE 22
    CMD ["/root/run.sh"]

    生成

    docker build -t centos7ssh

    相关文章

      网友评论

        本文标题:Docker技术入门与实战(带SSH的镜像)

        本文链接:https://www.haomeiwen.com/subject/uemkeqtx.html