Dockerfile构建#
参考:dockerfile
dockerfile 示例#
# 使用基础镜像,例如 Ubuntu
FROM ubuntu:20.04
# 更新软件包列表并安装必要的软件包
RUN apt-get update && apt-get install -y \
openssh-server
# 创建 SSH 运行目录
RUN mkdir /var/run/sshd
# 设置 root 密码(为了简单演示,实际应用中请使用安全的方式管理密码)
RUN echo 'root:password' | chpasswd
# 允许 root 通过 SSH 登录
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# 允许密码验证(默认是关闭的)
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
# 开放 22 端口
EXPOSE 22
# 启动 SSH 服务
CMD ["/usr/sbin/sshd", "-D"]