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:
- System shell
- Dagger Shell
- Dagger CLI
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
EOFType 'dagger' to start Dagger Shell in interactive mode and enter the command below.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-daggerdagger core container from --address="cgr.dev/chainguard/wolfi-base" \
with-exec --args="apk","add","go" \
with-directory --path="/src" --directory="https://github.com/golang/example#master" \
with-workdir --path="/src/hello" \
with-exec --args="go","build","-o","hello","." \
file --path="./hello" \
export --path="./hello-from-dagger" -
Use Dagger as an alternative to
docker run
.- System shell
- Dagger Shell
- Dagger CLI
dagger -c 'container | from cgr.dev/chainguard/wolfi-base | terminal'
Type 'dagger' to start Dagger Shell in interactive mode and enter the command below.container | from cgr.dev/chainguard/wolfi-base | terminal
dagger core container \
from --address=cgr.dev/chainguard/wolfi-base \
terminaltipIf 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 makesdagger -M
equivalent todagger core
. -
Call one of the auto-generated Dagger Functions:
- System shell
- Dagger Shell
- Dagger CLI
dagger -c 'container-echo "Welcome to Dagger!" | stdout'
Type 'dagger' to start Dagger Shell in interactive mode and enter the command below.container-echo "Welcome to Dagger!" | stdout
dagger call container-echo --string-arg="Welcome to Dagger!" stdout
tipWhen 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:
- System shell
- Dagger Shell
- Dagger CLI
dagger <<EOF
github.com/jpadams/daggerverse/trivy@v0.5.0 |
scan-image ubuntu:latest
EOFType 'dagger' to start Dagger Shell in interactive mode and enter the command below.github.com/jpadams/daggerverse/trivy@v0.5.0 | scan-image ubuntu:latest
dagger -m github.com/jpadams/daggerverse/trivy@v0.5.0 call \
scan-image --image-ref=ubuntu:latest -
List all the Dagger Functions available in a module using context-sensitive help:
- System shell
- Dagger Shell
- Dagger CLI
dagger -c '.help github.com/jpadams/daggerverse/trivy@v0.5.0'
Type 'dagger' to start Dagger Shell in interactive mode and enter the command below..help github.com/jpadams/daggerverse/trivy@v0.5.0
dagger -m github.com/jpadams/daggerverse/trivy@v0.5.0 call --help
-
List all the optional and required arguments for a Dagger Function using context-sensitive help:
- System shell
- Dagger Shell
- Dagger CLI
dagger -c 'github.com/jpadams/daggerverse/trivy@v0.5.0 | scan-image | .help'
Type 'dagger' to start Dagger Shell in interactive mode and enter the command below.github.com/jpadams/daggerverse/trivy@v0.5.0 | scan-image | .help
dagger -m github.com/jpadams/daggerverse/trivy@v0.5.0 call scan-image --help