1. 创建Dockerfile
- mkdir alpine
cd alpine
touch Dockerfile键入以下内容
#指定基础镜像
From alpine
#维护信息
MAINTAINER fangkai [email protected]
## 替换源
# 替换阿里云的源
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories
##
RUN apk update && \
apk add --no-cache openssh-server tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
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 && \
echo "root:admin" | chpasswd
#开放端口
EXPOSE 22
## 启动后台运行
CMD ["/usr/sbin/sshd", "-D"]
构建镜像
docker build -t alpine_ssh ./
运行容器
docker run -d -p 8022:22 alpine_ssh