Skip to content

gitea_runner内使用docker

目录


最近在用 gitea 搞自动化部署 但是发现 gitea_runner 内使用 docker 有问题,即使已经添加了 docker.sock

遂记录

在 runner 的 compose 中添加如下内容

yaml
version: "3"


services:

  runner:
    image: docker.io/gitea/act_runner:latest
    environment:
      GITEA_INSTANCE_URL: http://xxx
      GITEA_RUNNER_REGISTRATION_TOKEN: xxxx
      GITEA_RUNNER_NAME: action_runner_prod
      GITEA_RUNNER_LABELS: prod,ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster,self-hosted:host
    network_mode: host
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: sh -c "export https_proxy=http://10.9.0.1:7890 http_proxy=http://10.9.0.1:7890 all_proxy=http://10.9.0.1:7890 && \ # 如果觉得下载慢 可以设置代理
      apk add --no-cache docker-cli nodejs && \
      echo 'Node:' && node -v && \
      echo 'Docker:' && docker -v && \
      tail -f /dev/null"
  • 设置 self-hosted:host 这个 label
  • 在启动时安装 docker cli 和 node 用来运行一些脚本 可以不装

注意事项

这样操作之后 工作流里面就可以直接控制 宿主环境的 docker 警惕操作

参考资料

Copyright © 2022 田园幻想乡 浙ICP备2021038778号-1