You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions容器配置问题:无法正常启动systemd进程

GitHub Actions容器启动命令与docker run不一致的问题解决

问题原因

GitHub Actions的container模式有默认行为:它会自动替换容器镜像的ENTRYPOINT/CMD为tail -f /dev/null,目的是让容器保持长期运行,以便后续在容器内部执行job的各个步骤。而你直接执行docker run时,会使用镜像本身定义的启动命令(也就是/lib/systemd/systemd),这就是两者行为差异的根源。

解决方案

有两种方式可以复现docker run的原生效果:

方案一:直接在Steps中执行docker命令

放弃使用Actions的container字段,转而在job的步骤里直接调用docker run命令,完全复刻本地操作:

name: test
on:
  workflow_dispatch:
  push:

jobs:
  test:
    name: test
    runs-on: self-hosted
    steps:
      - name: 启动systemd容器
        run: docker run -d --name testmachine --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro jrei/systemd-ubuntu:20.04
      - name: 验证启动命令
        run: docker ps --filter name=testmachine --format "{{.Command}}"

方案二:覆盖Actions容器模式的默认Entrypoint/Command

如果坚持使用container字段,需要显式指定entrypoint和command来覆盖Actions的默认设置,强制使用镜像原生的启动命令:

name: test
on:
  workflow_dispatch:
  push:

jobs:
  test:
    name: test
    runs-on: self-hosted
    container:
      image: jrei/systemd-ubuntu:20.04
      volumes:
        - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
      options: --privileged
      entrypoint: /lib/systemd/systemd
      command: []  # 留空以使用镜像默认的命令参数

注意:这种方式下,容器启动后会运行systemd,但后续Actions步骤的执行逻辑需要调整,因为默认的步骤是期望在tail -f /dev/null的容器环境中执行命令,此时可能需要通过docker exec进入容器执行操作。

内容的提问来源于stack exchange,提问作者Shay Pinchasi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 11:54:20