0

I need to get rid of an external docker registry (like docker hub or aws ecr) in my workflow. Instead, I want to create a docker image in one job and push it to a local registry:2 so I can use it as a container for another job (below is a simplified example that just gets the point across)

# BEGIN
env:
  IMAGE: localhost:5000/myimage
jobs:
  set-up-image:
    runs-on: ubuntu-latest
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
        with:
          driver-opts: network=host
      - name: Build and push image
        uses: docker/build-push-action@v3
        id: docker-build-push
        with:
          context: .
          push: true
          file: ./docker/Dockerfile
          tags: ${{ env.IMAGE }}
  job-runs-into-container:
    needs: set-up-image
    runs-on: ubuntu-latest
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000
    container:
      image: ${{ env.IMAGE }}
      options: --user root
    steps:
      - name: Run some actions into docker container
        run: ...........
# Rest of the code

Here, the problem is immediately noticeable that the local docker registry service ceases to exist after the first work, and in the second I can no longer get a container from it.

Alternatively, I could use cross-work artifact transfer to run this container inside a second job (or just work within the same job), but then I would have to execute actions from the second job using the

docker exec 

command, which I want to avoid.

In search of a solution, I studied other similar questions, but they did not contain information suitable for me:

  1. In a github actions workflow, is there a way to have multiple jobs reuse the same setup? - Here we are talking more about caching some actions.
  2. Github actions share workspace/artifacts between jobs? - As I wrote above, when transferring artifacts, I will not be able to run work inside this container and I will have to use the docker exec command
  3. Reuse portion of github action across jobs - Here we are talking about reusing sections of code in jobs.

0 Answers0