Skip to content

Docker ​

action: docker.run runs one step in a container. Dagu creates the container from an image (or uses a running one), runs the command, streams its output to the step log, and uses the container's exit code as the step result.

To run run: steps in containers, or every step of a DAG in one shared container, use the container field. Use docker.run when a step needs Docker Engine options such as memory limits or privileged mode.

Basic Usage ​

yaml
steps:
  - id: hello
    action: docker.run
    with:
      image: alpine:3
      command: echo "Hello from a container"
      auto_remove: true

The step log shows Hello from a container, and the step succeeds when the container exits with code 0. Without auto_remove: true, the stopped container stays on the Docker host after the step.

Mount Files ​

volumes takes source:target[:ro|rw]. working_dir sets the directory inside the container.

yaml
working_dir: .

steps:
  - id: build
    action: docker.run
    with:
      image: golang:1.24
      working_dir: /src
      volumes:
        - ./app:/src
        - go-cache:/root/go/pkg/mod
      command: go build -o bin/app ./cmd/app
      auto_remove: true
  • A source that starts with /, ., or ~, or contains a slash, is a bind mount. A relative path resolves against the step working directory.
  • Any other source, such as go-cache, is a named Docker volume.
  • $VAR and ${VAR} in the source expand from the Dagu process environment. A missing variable fails the step before the container starts.

When Dagu itself runs in Docker, the daemon resolves bind sources on the host, not inside the Dagu container. Use paths that exist on the host, or named volumes.

Use a Shell in the Container ​

command is not run through a shell. Dagu splits the string into arguments, so |, &&, >, and $VAR reach the program as plain text. Set shell to run the command with a shell inside the container:

yaml
steps:
  - id: count_files
    action: docker.run
    with:
      image: alpine:3
      shell: ["sh"]
      command: ls /etc | wc -l
      auto_remove: true

Dagu adds -c when the shell arguments lack it. Dagu references such as ${params.date} are resolved on the host before the container starts.

Run Several Commands ​

A list runs each command in the same container, in order, and stops at the first failure. Files written by one command are visible to the next.

yaml
working_dir: .

steps:
  - id: test
    action: docker.run
    with:
      image: node:22
      working_dir: /app
      volumes:
        - ./web:/app
      command:
        - npm ci
        - npm test
      auto_remove: true

With a list, Dagu starts the container with a keep-alive process instead of the image's default command, then runs each entry with docker exec.

Run in an Existing Container ​

container_name without image runs the command in a container that is already running, such as a Docker Compose service. Dagu waits up to 120 seconds for it to be running.

yaml
steps:
  - id: migrate
    action: docker.run
    with:
      container_name: app-web
      exec:
        User: www-data
        WorkingDir: /var/www
      command: php artisan migrate --force

exec sets Docker exec options and is valid only with container_name.

Set Environment Variables and Limits ​

container, host, and network pass Docker Engine API objects through unchanged. Keys use the API names, matched without regard to case.

yaml
params:
  - region: eu-west-1

steps:
  - id: report
    action: docker.run
    with:
      image: ghcr.io/example/report:1.4
      container:
        Env:
          - REGION=${params.region}
          - LOG_LEVEL=info
      host:
        Memory: 536870912 # 512 MiB
        NanoCpus: 1000000000 # 1 CPU
      command: ./generate --out /tmp/report.csv
      auto_remove: true

The container receives the image's variables and container.Env. Step and DAG env are not passed in, so reference them with ${env.NAME} as above. CPU and memory limits from DAG Run Resource Limits also apply to new containers.

Configuration ​

action: container.run is an alias of docker.run. Set image, container_name, or both.

FieldRequiredDefaultDescription
imageOne of image or container_nameImage for a new container.
container_nameOne of image or container_nameWithout image: a running container to exec into. With image: the name of the new container.
commandNoImage CMDCommand for the container. A string is split into arguments; a list runs each entry in order.
shellNoNoneShell inside the container that runs command, such as ["bash", "-o", "pipefail"].
pullNomissingalways, missing, never, or fallback. true means always, false means never.
auto_removeNofalseRemove the container after the step ends.
platformNoDaemon platformImage platform, such as linux/arm64.
working_dirNoImage defaultWorking directory in the container.
volumesNoNoneMounts as source:target[:ro|rw].
containerNoNoneDocker container config, such as Env, User, Entrypoint, Labels.
hostNoNoneDocker host config, such as Memory, NanoCpus, Privileged, NetworkMode.
networkNoNoneDocker networking config, such as EndpointsConfig.
execNoNoneDocker exec options, such as User, WorkingDir, Env. Requires container_name.

Pull policies:

pullBehavior
alwaysPull before every run.
missingPull only when no matching local image exists.
neverUse the local image only.
fallbackTry to pull; on failure, use the local image. Fail if neither works.

Output ​

  • Logs: the container's stdout and stderr go to the step log. On failure, the step error includes the last lines of stderr.
  • Exit code: the container's exit code (or the failing command's, for a list) is the step's exit code.
  • Values: capture stdout with output: NAME, or save it as an artifact with stdout.artifact. See Capturing Stdout.

Registry Authentication ​

registry_auths at the DAG level supplies credentials when Dagu pulls an image. Keys are registry hosts as they appear in image names.

yaml
registry_auths:
  ghcr.io:
    username: ${env.GITHUB_USER}
    password: ${env.GITHUB_TOKEN}
  gcr.io:
    auth: ${env.GCR_AUTH_BASE64} # base64 of username:password

steps:
  - id: analyze
    action: docker.run
    with:
      image: ghcr.io/example/analyzer:2
      command: analyze --all
      auto_remove: true
  • registry_auths also accepts a whole Docker config JSON string, as in ~/.docker/config.json: registry_auths: ${env.DOCKER_AUTH_CONFIG}.
  • When registry_auths is set but has no entry for an image's registry, Dagu reads DOCKER_AUTH_CONFIG from the Dagu process environment.
  • Values resolve DAG references such as ${env.NAME}. Declare host variables in DAG env or secrets first.

The same credentials apply to the container field.

Docker Daemon Access ​

Dagu talks to the Docker Engine API. Containers start on whichever daemon Dagu connects to.

Where Dagu runsSetup
On a Docker hostNothing. Dagu uses the local Docker socket.
Inside DockerMount the host socket. Containers start as siblings on the host.
Remote daemonSet DOCKER_HOST and, for TLS, DOCKER_TLS_VERIFY and DOCKER_CERT_PATH on the Dagu process.
PodmanSet DAGU_CONTAINER_RUNTIME=podman. Set DAGU_PODMAN_HOST when the socket is not unix:///run/podman/podman.sock.
bash
DAGU_CONTAINER_RUNTIME=podman \
DAGU_PODMAN_HOST=unix:///run/user/1000/podman/podman.sock \
dagu start-all

These are process settings, not DAG fields. In a distributed setup, every worker that runs container steps needs daemon access. See Podman sandbox setup for socket details.

Errors and Limits ​

  • A step with neither image nor container_name fails validation.
  • exec with image and no container_name fails validation.
  • A multi-line command string fails validation. Use a list, or shell with a one-line command.
  • With container_name and image, a running container of that name is reused; a stopped one is removed and created again.
  • timeout_sec and a stop request stop the container with the step's signal_on_stop (or the daemon default), then kill it after the DAG's max_clean_up_time_sec.

Dagu is open source under the GNU General Public License v3.0.