docker
A collection of functions for building, saving and publishing your Docker based projectsInstallation
dagger install github.com/purpleclay/daggerverse/docker@v0.3.1Entrypoint
Return Type
Docker !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| registry | String | "docker.io" | the address of the registry to authenticate with |
| username | String | - | the username for authenticating with the registry |
| password | Secret | - | the password for authenticating with the registry |
Example
dagger -m github.com/purpleclay/daggerverse/docker@3b92d1922856ca5ba6205c33e8758150a0c18687 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 dagger module
build() 🔗
Build an image using a Dockerfile. Supports cross-compilation
Examples:
Build an image using the current directory as the context
$ dagger call build –dir .
Build an image using cross-compilation
$ dagger call build –dir . –platfrom “linux/amd64,linux/arm64”
Build an image using build-args and a build target
$ dagger call build –dir . –args “VERSION=0.1.0” –target debug
Return Type
Build !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| dir | Directory ! | - | the path to a directory that will be used as the docker context |
| file | String | "Dockerfile" | the path to the Dockfile |
| args | [String ! ] | - | a list of build arguments in the format of arg=value |
| target | String | - | the name of a target build stage |
| platform | [String ! ] | ["linux/amd64"] | a list of target platforms for cross-compilation |
Example
dagger -m github.com/purpleclay/daggerverse/docker@3b92d1922856ca5ba6205c33e8758150a0c18687 call \
build --dir DIR_PATHfunc (m *MyModule) Example(dir *dagger.Directory) *dagger.DockerBuild {
return dag.
Docker().
Build(dir)
}@function
def example(dir: dagger.Directory) -> dagger.DockerBuild:
return (
dag.docker()
.build(dir)
)@func()
example(dir: Directory): DockerBuild {
return dag
.docker()
.build(dir)
}Build 🔗
DockerBuild contains an image built from the provided Dockerfile, it serves as an intermediate type for chaining other functions. If multiple platforms were provided, then multiple images will exist
save() 🔗
Save the built image as a tarball ready for exporting
Examples:
Save the tarball with the given name
$ dagger call build –dir . save –name awesome_service
Return Type
Directory !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| name | String | "image" | a name for the exported tarball, will automatically be suffixed by its platform (e.g. image_linux_amd64.) |
Example
dagger -m github.com/purpleclay/daggerverse/docker@3b92d1922856ca5ba6205c33e8758150a0c18687 call \
build --dir DIR_PATH \
savefunc (m *MyModule) Example(dir *dagger.Directory) *dagger.Directory {
return dag.
Docker().
Build(dir).
Save()
}@function
def example(dir: dagger.Directory) -> dagger.Directory:
return (
dag.docker()
.build(dir)
.save()
)@func()
example(dir: Directory): Directory {
return dag
.docker()
.build(dir)
.save()
}publish() 🔗
Publish the built image to a target registry
Examples:
Publish a built image to the ttl.sh registry
$ dagger call build –dir . publish –ref ttl.sh/purpleclay-test
Publish a cross-compiled image to the ttl.sh registry with multiple tags
$ dagger call build –dir . –platform “linux/amd64,linux/arm64” publish –ref ttl.sh/purpleclay-test –tags “latest,0.1.0”
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| ref | String ! | - | a fully qualified image reference without tags |
| tags | [String ! ] | ["latest"] | a list of tags that should be published with the image |
Example
dagger -m github.com/purpleclay/daggerverse/docker@3b92d1922856ca5ba6205c33e8758150a0c18687 call \
build --dir DIR_PATH \
publish --ref stringfunc (m *MyModule) Example(ctx context.Context, dir *dagger.Directory, ref string) string {
return dag.
Docker().
Build(dir).
Publish(ctx, ref)
}@function
async def example(dir: dagger.Directory, ref: str) -> str:
return await (
dag.docker()
.build(dir)
.publish(ref)
)@func()
async example(dir: Directory, ref: string): Promise<string> {
return dag
.docker()
.build(dir)
.publish(ref)
}