附带ssh的alpine镜像

附带ssh的alpine镜像

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

# 作者描述信息
MAINTAINER alpine_sshd_service

# 替换阿里源,安装openssh,并修改配置文件和生成key,并且同步时间。
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
        && apk update \
        && apk add --no-cache openssh tzdata \
        && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
        && sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config \
        && ssh-keygen -t dsa -P "" -f /etc/ssh/ssh_host_dsa_key \
        && 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 \
        && echo "root:123." | chpasswd

# 开放22端口
EXPOSE 22

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

创建镜像

docker build -t alpine-ssh .

创建容器

docker run -d --name alpine-ssh -p 22:22 alpine-ssh

连接

ssh root@localhost
posted @ 2022-12-08 12:46  一年`  阅读(69)  评论(0编辑  收藏  举报