带 systemd 的 ubuntu 系统
dockerfile 文件
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y init && apt-get clean all
#创建的镜像能够安装ssh并允许密码登录
RUN apt-get update && apt-get install -y openssh-server nano lsof
RUN mkdir /var/run/sshd
RUN echo 'root:password' | chpasswd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN /usr/sbin/sshd -D &
EXPOSE 22
build
docker build -f ./dockerfile . -t msecth/ubuntu-amd64-systemd:24.04
启动命令
#直接占用宿主机端口
docker run -tid --name ubuntu --network host --privileged=true msecth/ubuntu-amd64-systemd:24.04 /sbin/init
#映射端口
docker run -tid --name ubuntu -p 2222:22 --privileged=true msecth/ubuntu-amd64-systemd:24.04 /sbin/init
25.10 更新
FROM ubuntu:25.10
# 创建的镜像能够安装ssh并允许密码登录
# 将多个RUN指令合并,并清理apt缓存,以减小镜像体积
RUN apt-get update && \
apt-get install -y openssh-server sudo nano lsof vim curl wget && \
rm -rf /var/lib/apt/lists/*
# 设置 root 用户的密码。警告:这会将密码硬编码在镜像中,非常不安全!
# 仅用于测试环境。
RUN echo 'root:password' | chpasswd
# 修改ssh配置文件,允许root用户通过密码登录
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# 同样,允许空密码(如果需要,但不推荐)和使用PAM
RUN sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
# 暴露容器的22端口,以便外部访问
EXPOSE 22
# 容器启动时执行的命令
# 1. 创建 sshd 运行时需要的目录
# 2. 启动 sshd 服务,并使用 -D 参数使其在前台运行,防止容器启动后立即退出
CMD mkdir -p /var/run/sshd && /usr/sbin/sshd -D
Content type
Image
Digest
sha256:ea645bfb9…
Size
85.5 MB
Last updated
about 1 year ago
docker pull msecth/ubuntu-amd64-systemd:25.10