liveBook · Manning

Docker container action

As explained in GitHub Actions in Action: Continuous integration and delivery for DevOps

A Docker container action is a GitHub Action executed inside a Docker container that packages its dependencies with the action.

A Docker container action is a GitHub Action executed in a Docker container, packaging its dependencies for consistent execution. It runs only on Linux and starts more slowly than a JavaScript action because the image must be retrieved or built and the container started. section 4.1 section 4.1.1

Each action has an action.yml or action.yaml file in its own repository or folder. Its runs section identifies the container action; the image can reference a registry image or use Dockerfile to build from files supplied with the action. section 4.1 section 4.1.1

Listing 4.1 An example action.yml file for a Docker container action
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
inputs:
  input_one:
    description: 'Some info passed to the container
    required: false
  input_two:
    default: 'some default value'
    description: 'Some info passed to the container'
    required: false
runs:                                                        #1
  using: 'docker'
  image: 'docker://ghcr.io/wulfland/container-demo:latest'
  args:                                                      #2
    - ${{ inputs.input_one }}
    - ${{ inputs.input_two }}
  env:                                                       #3
      VARIABLE1: ${{ inputs.input_one }}
      VARIABLE2: ${{ inputs.input_two }}
#1 runs: defines the type of action—here, this is the Docker image.
#2 args: you can pass in inputs as arguments to Docker when the container is created.
#3 env: you can pass in inputs as environment variables to be available at container run time.

Inspect the action.yml listing to see inputs mapped into container arguments and environment variables. section 4.1.1

Configure the action around these implementation points:

  • Declare inputs with descriptions, required flags, and optional defaults. section 4.1.1
  • Pass input values through args or environment variables to the container. section 4.1.1
  • Choose a registry image or build a Dockerfile at runtime. section 4.1.1
  • Install Docker on a self-hosted runner before executing a Docker-based action; target suitable runner capabilities with labels. section 6.1.6

Tested action workflow

Create a Docker container action that accepts input and output parameters, then run a CI build whenever one of the action's files changes to test it. section 4.3

How GitHub Actions in Action: Continuous integration and delivery for DevOps covers it

How deep it goes
Defines metadata, images, inputs, arguments, and environment variables, but defers detailed action implementation and output processing.
Examples
Uses an action.yml listing with registry image ghcr.io/wulfland/container-demo:latest, input mappings, and a CI test lab.
What you can do after
Build it from scratch with action.yml, container inputs, and CI tests for input and output behavior.
How it connects
Contrasts with JavaScript actions and composite actions, and depends on Docker images, Dockerfiles, registries, and self-hosted runners.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GitHub Actions in Action: Continuous integration and delivery for DevOps. The section links point to the parts of the book it draws on.