Skip to main content

Dagger CLI

The Dagger CLI lets you call both the core and extended Dagger API (the core APIs plus the new APIs provided by external Dagger modules) directly from the command-line.

You can call the API interactively (dagger) or non-interactively (dagger -c, dagger call, or dagger core).

Here are a few examples:

  • Create a simple pipeline that is fully satisfied by the core Dagger API, without needing to program a Dagger module:

    dagger <<EOF
    container |
    from cgr.dev/chainguard/wolfi-base |
    with-exec apk add go |
    with-directory /src https://github.com/golang/example#master |
    with-workdir /src/hello |
    with-exec -- go build -o hello . |
    file ./hello |
    export ./hello-from-dagger
    EOF
  • Use Dagger as an alternative to docker run.

    dagger -c 'container | from cgr.dev/chainguard/wolfi-base | terminal'
    tip

    If only the core Dagger API is needed, the -M (--no-mod) flag can be provided. This results in quicker startup, because the Dagger CLI doesn't try to find and load a current module. This also makes dagger -M equivalent to dagger core.

  • Call one of the auto-generated Dagger Functions:

    dagger -c 'container-echo "Welcome to Dagger!" | stdout'
    tip

    When using the Dagger CLI, all names (functions, arguments, struct fields, etc) are converted into a shell-friendly "kebab-case" style.

  • Modules don't need to be installed locally. Dagger lets you consume modules from GitHub repositories and call their Dagger Functions as though you were calling them locally:

    dagger <<EOF
    github.com/jpadams/daggerverse/trivy@v0.5.0 |
    scan-image ubuntu:latest
    EOF
  • List all the Dagger Functions available in a module using context-sensitive help:

    dagger -c '.help github.com/jpadams/daggerverse/trivy@v0.5.0'
  • List all the optional and required arguments for a Dagger Function using context-sensitive help:

    dagger -c 'github.com/jpadams/daggerverse/trivy@v0.5.0 | scan-image | .help'