alpine用dockerfile创建的ssh镜像

# 指定创建的基础镜像
FROM alpine:latest

#ADD run.sh /root/
ADD .bashrc /root/
ADD .profile /root/
ADD passwd /etc/
# 使用阿里云镜像, 设置默认时区为Asia/Shanghai
RUN { \
        echo "http://mirrors.aliyun.com/alpine/latest-stable/main/"; \
        echo "http://mirrors.aliyun.com/alpine/latest-stable/community/"; \
        } > /etc/apk/repositories \
        && apk add --no-cache busybox-extras bash-completion tzdata bash openssh-server vim net-tools  \
        && \cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 修改配置文件和生成key
RUN sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
    ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
    ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
    ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key
RUN echo root:wyt123456 | chpasswd

# 开放22端口
EXPOSE 22

# 执行ssh启动命令
CMD ["/usr/sbin/sshd", "-D"]