How to Write a Docker Container Action in GitHub Actions
A Docker container action runs your entrypoint inside an image the runner builds from a Dockerfile.
Set runs.using: "docker" and runs.image: "Dockerfile". The runner builds the image, then runs the entrypoint. Pass inputs through runs.args and read them as positional arguments or env vars.
Steps
- Write a
Dockerfilewith anENTRYPOINT. - Set
runs.using: "docker"andruns.image: "Dockerfile". - Forward inputs with
runs.argsreferencing${{ inputs.<name> }}. - Read the args in the entrypoint script.
action.yml
action.yml
name: 'Say hello'
inputs:
who:
description: 'Name to greet'
default: 'world'
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.who }}Dockerfile
Dockerfile
FROM alpine:3.20
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]entrypoint.sh
Terminal
#!/bin/sh -l
echo "Hello, $1!"
echo "greeting=Hello, $1!" >> "$GITHUB_OUTPUT"Gotchas
- Docker actions run only on Linux runners, not on macOS or Windows.
- The workspace is mounted at
/github/workspace, which the entrypoint runs from.
Related guides
How to Pass Secrets to a Docker Container ActionPass a secret into a Docker container action by forwarding it as an env var from the workflow step, then read…
How to Write a Composite Action in GitHub ActionsBuild a composite action by creating an action.yml with runs.using composite and a steps list, then call the…
How to Set Outputs From a Custom Action With GITHUB_OUTPUTSet an output from a composite or container action by appending name=value to the GITHUB_OUTPUT file, then ex…