"runs-on" vs "container"

Hey!
I tried to find documentation on this, but I couldn’t find anything.

When we have:

jobs:
  job_name:
    name: Job Name
    runs-on: ubuntu-latest
    container:
      image: docker:latest

Does container override runs-on?
Or, does the job spin up a container with whatever image is assigned to ubuntu-latest (in config.yaml), which will then spin up a separate container running docker:latest?

Note – in my env, both Gitea and the Actions Runner are running on docker. The Actions Runner spins up containers on the host’s docker.sock.

For cases where I want to specify a volume to mount…

Is this something valid to do? Omitting container.image, and specifying the image alias in runs-on:

jobs:
  job_name:
    name: Job Name
    runs-on: docker-latest
    container:
      volumes:
        - /path1/:/path1/

Or, alternatively, omitting runs-on:

jobs:
  job_name:
    name: Job Name
    container:
      image: docker:latest
      volumes:
        - /path1/:/path1/

In other words, what I’m looking for is to prevent doing this:

Actions Runner (running gitea/act_runner:latest)
Spins up gitea/runner-images:ubuntu-latest (based on runs-on)
Spins up docker:latest (based on container)

And instead, do this:

Actions Runner (running gitea/act_runner:latest)
Spins up docker:latest (based on container)

(for cases where I want to specify a volume to be mounted, for that specific job, and hence the reason to use the container node)

Thanks!

1 Like

Ditto. I’d like to pass a file, or a variable, down from the action runner to the jobs, but I’m confused on the difference of runs-on vs container.

Here are a couple observations. I can speak to the number of running containers.

I use runs-on: to select the runner. I use container: when I need a job-specific image.

When I specify with both runs-on: and container:, I see:

$ docker container ls -a
CONTAINER ID   IMAGE
------------   gitea.myinstance.com/public/syncthing-android-builder:latest
------------   gitea/act_runner:latest

When I specify only runs-on:, I see:

$ docker container ls -a
CONTAINER ID   IMAGE
------------   gitea/runner-images:ubuntu-latest
------------   gitea/act_runner:latest

It appears container: overrides the image used to run the job container which results in only two images running.

Here are snippets from the workflow yaml files:

  • With both runs-on: and container: specified:
jobs:
  build:
    name: Debug Build
    runs-on: ubuntu-latest
    container: gitea.myinstance.com/public/syncthing-android-builder:latest
  • With only runs-on: specified:
jobs:
  Explore-Gitea-Actions:
    runs-on: [ubuntu-latest]
    steps:
      ...
      - name: Long Sleep
        run: |
          sleep 10000000

Note: the sleep 10000000 has been useful when I need to keep the job container running to debug build issues inside the running job container.

1 Like

Oh, many thanks for this!

That was very useful and informative.

That’s very good, if that’s how it works, then!! :slight_smile: