首页 > 解决方案 > 如何在自己的 docker 容器中使用 github 操作/checkout@v2

问题描述

我有自己的 php 图像,我想用它来为我的项目运行测试。

container: rela589n/doctrine-event-sourcing-php:latest

services:
  test_db:
    image: postgres:13-alpine
    env:
      POSTGRES_DB: des
      POSTGRES_USER: des_user
      POSTGRES_PASSWORD: p@$$w0rd

steps:
  - uses: actions/checkout@v2

  - whatever_needed_to_run_tests_inside_container

这在结帐操作中失败,并出现以下错误:

EACCES: permission denied, open '/__w/doctrine-event-sourcing/doctrine-event-sourcing/6977c4d4-3881-44e9-804e-ae086752556e.tar.gz'

这是合乎逻辑的,因为在新的 docker 容器中没有这样的文件夹结构。我想做的是在提供的虚拟机中运行结帐操作runs-on: ubuntu-20.04并为 docker 配置卷,以便它可以访问代码。但是,我不知道这样做既不是一个好习惯,也不知道如何实现这一点。我想即使可以这样做,它也不适用于其他操作。

标签: phpdockergithubcontainersgithub-actions

解决方案


Had the same issue when trying to use my own Docker image. In my case, installing everything I need on the fly was not an option, so I had to fix this issue. It appears that GitHub runs the Docker image with user 1001 named runner and group 121 named docker. After adding the group, adding the user and adding the user to sudoers the problem was solved. Notice that the checkout path starts with /_w which is strange. If I perform actions/checkout@v2 without my container, the path is /home/runner. Not sure how to solve that yet.


推荐阅读