Dockerfile:
FROM centos:centos8 MAINTAINER docker_user (archer2018@docker.com) ADD CentOS8-Base.repo /etc/yum.repos.d/ RUN yum makecache RUN yum install -y openssh-server* RUN ssh-keygen -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key -q RUN ssh-keygen -t ecdsa -N '' -f /etc/ssh/ssh_host_ecdsa_key -q RUN ssh-keygen -t ed25519 -N '' -f /etc/ssh/ssh_host_ed25519_key -q RUN sed -i 's/^AuthorizedKeysFile.*/AuthorizedKeysFile ~/.ssh/authorized_keys/g' /etc/ssh/sshd_config RUN echo 'RSAAuthentication yes' >> /etc/ssh/sshd_config ADD id_rsa.pub /root/.ssh/authorized_keys ADD run.sh /root/ RUN chmod 755 /root/run.sh EXPOSE 22 CMD ["/root/run.sh"]
CentOS8-Base.repo
[extras] gpgcheck=1 gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-8 enabled=1 baseurl=http://mirrors.tencentyun.com/centos/$releasever/extras/$basearch/ name=Qcloud centos extras - $basearch [os] gpgcheck=1 gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-8 enabled=1 baseurl=http://mirrors.tencentyun.com/centos/$releasever/os/$basearch/ name=Qcloud centos os - $basearch [updates] gpgcheck=1 gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-8 enabled=1 baseurl=http://mirrors.tencentyun.com/centos/$releasever/updates/$basearch/ name=Qcloud centos updates - $basearch
run.sh
#!/bin/bash /usr/sbin/sshd -D
注意:公钥文件id_rsa.pub 从home目录复制到Dockerfile目录