Skip to content
Latchkey

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 Dockerfile with an ENTRYPOINT.
  • Set runs.using: "docker" and runs.image: "Dockerfile".
  • Forward inputs with runs.args referencing ${{ 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

Run this faster and cheaper on Latchkey managed runners. Start free →