docker
This module has been generated via dagger init and serves as a reference tobasic module structure as you get started with Dagger.
Two functions have been pre-created. You can modify, delete, or add to them,
as needed. They demonstrate usage of arguments and return types using simple
echo and grep commands. The functions can be called from the dagger CLI or
from one of the SDKs.
The first line in this comment block is a short description line and the
rest is a long description with more detail on the module's purpose or usage,
if appropriate. All modules should have a short description.
Installation
dagger install github.com/broadsage/dagger-modules/modules/docker@39f080e96f3c689feb7def1a2be12c36264a1209Entrypoint
Return Type
Docker ! Example
dagger -m github.com/broadsage/dagger-modules/modules/docker@39f080e96f3c689feb7def1a2be12c36264a1209 call \
func (m *MyModule) Example() *dagger.Docker {
return dag.
Docker()
}@function
def example() -> dagger.Docker:
return (
dag.docker()
)@func()
example(): Docker {
return dag
.docker()
}Types
Docker 🔗
Docker module for building and publishing container images.
build() 🔗
Build a container image from a Dockerfile.
Args: context: Directory containing the Dockerfile and build context dockerfile: Path to the Dockerfile relative to context (default: “Dockerfile”)
Returns: Built container
Return Type
Container !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| context | Directory ! | - | A directory. |
| dockerfile | String ! | "Dockerfile" | No description provided |
Example
dagger -m github.com/broadsage/dagger-modules/modules/docker@39f080e96f3c689feb7def1a2be12c36264a1209 call \
build --context DIR_PATH --dockerfile stringfunc (m *MyModule) Example(context *dagger.Directory, dockerfile string) *dagger.Container {
return dag.
Docker().
Build(context, dockerfile)
}@function
def example(context: dagger.Directory, dockerfile: str) -> dagger.Container:
return (
dag.docker()
.build(context, dockerfile)
)@func()
example(context: Directory, dockerfile: string): Container {
return dag
.docker()
.build(context, dockerfile)
}push() 🔗
Build and push a container image to a registry.
This is the main function - simple and focused. Use this for all registries. Orchestrate multiple registries in your CI/CD (GitHub Actions, GitLab CI, etc.).
Args: context: Directory containing the Dockerfile and build context image_name: Name of the image (e.g., “myorg/myapp” or “org/app” for GHCR) username: Registry username for authentication password: Registry password/token secret for authentication registry: Registry URL (default: “docker.io”). Examples: - “docker.io” (Docker Hub) - “ghcr.io” (GitHub Container Registry) - “registry.gitlab.com” (GitLab) - “gcr.io” (Google Container Registry) tags: List of tags to apply (default: [“latest”]) dockerfile: Path to the Dockerfile relative to context (default: “Dockerfile”)
Returns: Published image references with digests
Example:
# Docker Hub
dagger call push –context=. –image-name=user/app –username=user
–password=env:DOCKERHUB_TOKEN –registry=docker.io
–tags=latest –tags=v1.0
# GHCR
dagger call push --context=. --image-name=org/app --username=user \
--password=env:GITHUB_TOKEN --registry=ghcr.io --tags=latest
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| context | Directory ! | - | A directory. |
| imageName | String ! | - | No description provided |
| username | String ! | - | No description provided |
| password | Secret ! | - | A reference to a secret value, which can be handled more safely than the value itself. |
| registry | String ! | "docker.io" | No description provided |
| tags | [String ! ] | null | No description provided |
| dockerfile | String ! | "Dockerfile" | No description provided |
Example
dagger -m github.com/broadsage/dagger-modules/modules/docker@39f080e96f3c689feb7def1a2be12c36264a1209 call \
push --context DIR_PATH --image-name string --username string --password env:MYSECRET --registry string --dockerfile stringfunc (m *MyModule) Example(ctx context.Context, context *dagger.Directory, imageName string, username string, password *dagger.Secret, registry string, dockerfile string) string {
return dag.
Docker().
Push(ctx, context, imageName, username, password, registry, dockerfile)
}@function
async def example(context: dagger.Directory, image_name: str, username: str, password: dagger.Secret, registry: str, dockerfile: str) -> str:
return await (
dag.docker()
.push(context, image_name, username, password, registry, dockerfile)
)@func()
async example(context: Directory, imageName: string, username: string, password: Secret, registry: string, dockerfile: string): Promise<string> {
return dag
.docker()
.push(context, imageName, username, password, registry, dockerfile)
}