Skip to main content

Aliases

You can change the name of an exposed field or function to work around a reserved keyword or some other naming conflict, but still be able to expose the desired name in the Dagger API. For example, using import_ in the language, but import in the Dagger API. To do so, simply add the alias as a parameter of the corresponding decorator.

Here is an example of a module with the field ctr aliased as container and the function displayVersion aliased as version:

import { dag, Container, object, func, field } from "@dagger.io/dagger"

@object()
class MyModule {
@field("container")
ctr: Container

constructor(ctr?: Container) {
this.ctr = ctr ?? dag.container().from("alpine:3.14.0")
}

@func("version")
async displayVersion(): Promise<string> {
return await this.ctr
.withExec(["/bin/sh", "-c", "cat /etc/os-release | grep VERSION_ID"])
.stdout()
}
}

Field and function names are overridden by their aliases in the output of dagger functions:

dagger functions
Name Description
container -
version -