Aspirerelease/17.0
Watch Aspire live streamsDocsTry Aspire

ContainerResource

Handle
📦 Aspire.Hosting v17.0.0

A resource that represents a specified container.

type ContainerResource interface {
IComputeResource
Resource
ResourceWithArgs
ResourceWithEndpoints
ResourceWithEnvironment
ResourceWithWaitSupport
}

Methods

Changes the resource to be published as a connection string reference in the manifest.
PublishAsConnectionString() ContainerResource
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodPublishAsContainerbuilder
Changes the resource to be published as a container in the manifest.
PublishAsContainer() ContainerResource
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithBindMountbuilder
Adds a bind mount to a container resource.
WithBindMount(
source string,
target string,
options ...*WithBindMountOptions,
) ContainerResource
sourcestringThe source path of the mount. This is the path to the file or directory on the host, relative to the AppHost project directory.
targetstringThe target path where the file or directory is mounted in the container.
options...*WithBindMountOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithBindMountOptions argument.

IsReadOnly*boolA flag that indicates if this is a read-only mount.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithBuildArgbuilder
Adds a build argument when the container is built from a Dockerfile.
WithBuildArg(
name string,
value any,
) ContainerResource
namestringThe name of the build argument.
valueanyThe build argument value, either a string or a parameter resource.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithBuildSecretbuilder
Adds a secret build argument when the container is built from a Dockerfile.
WithBuildSecret(
name string,
value ParameterResource,
) ContainerResource
namestringThe name of the secret build argument.
valueParameterResourceThe resource builder for a parameter resource.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Adds container certificate path overrides used for certificate trust at run time.
WithContainerCertificatePaths(options ...*WithContainerCertificatePathsOptions) ContainerResource
options...*WithContainerCertificatePathsOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithContainerCertificatePathsOptions argument.

CustomCertificatesDestination*stringThe destination path in the container where custom certificates will be copied.
DefaultCertificateBundlePaths[]stringDefault certificate bundle paths in the container that will be replaced.
DefaultCertificateDirectoryPaths[]stringDefault certificate directory paths in the container that may be appended.
ContainerResource

The updated resource builder.

Returns a handle; failures surface later via Err().

methodWithContainerFilesbuilder
Creates or updates files and folders in a container by copying them from a source path on the host.
WithContainerFiles(
destinationPath string,
sourcePath string,
options ...*ContainerFilesOptions,
) ContainerResource
destinationPathstringThe destination absolute path in the container.
sourcePathstringThe source path on the host to copy files from.
options...*ContainerFilesOptionsOptional settings, described under Options.

Optional parameters are passed as the existing *ContainerFilesOptions struct.

ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Creates or updates files and/or folders at the destination path in the container using entries produced by a callback.
WithContainerFilesCallback(
destinationPath string,
callback func(arg1 ContainerFileSystemCallbackContext, arg2 *CancellationToken) []ContainerFileSystemItem,
options ...*ContainerFilesOptions,
) ContainerResource
destinationPathstringThe destination absolute path in the container.
callbackfunc(arg1 ContainerFileSystemCallbackContext, arg2 *CancellationToken) []ContainerFileSystemItemcallbackA callback that returns the file system entries to create or update. Use the factory methods on ContainerFileSystemCallbackContext (createFile, createDirectory, createCertificateFile) to build the entries.
options...*ContainerFilesOptionsOptional settings, described under Options.

Optional parameters are passed as the existing *ContainerFilesOptions struct.

ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithContainerNamebuilder
Overrides the default container name for this resource. By default Aspire generates a unique container name based on the resource name and a random postfix (or a postfix based on a hash of the AppHost project path for persistent container resources). This method allows you to override that behavior with a custom name, but could lead to naming conflicts if the specified name is not unique.
WithContainerName(name string) ContainerResource
namestringThe desired container name. Must be a valid container name or your runtime will report an error.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Adds a network alias to container resource.
WithContainerNetworkAlias(alias string) ContainerResource
aliasstringThe network alias for the container.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Adds a callback to be executed with a list of arguments to add to the container runtime run command when a container resource is started.
WithContainerRuntimeArgs(args []string) ContainerResource
args[]stringThe arguments to be passed to the container runtime run command when the container resource is started.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithDockerfilebuilder
Causes Aspire to build the specified container image from a Dockerfile.
WithDockerfile(
contextPath string,
options ...*WithDockerfileOptions,
) ContainerResource
contextPathstringPath to be used as the context for the container image build.
options...*WithDockerfileOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithDockerfileOptions argument.

DockerfilePath*stringPath to the Dockerfile relative to the contextPath. Defaults to "Dockerfile" if not specified.
Stage*stringThe stage representing the image to be published in a multi-stage Dockerfile.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Configures the resource to use a programmatically generated Dockerfile
WithDockerfileBuilder(
contextPath string,
callback func(arg DockerfileBuilderCallbackContext),
options ...*WithDockerfileBuilderOptions,
) ContainerResource
contextPathstringPath to be used as the context for the container image build.
callbackfunc(arg DockerfileBuilderCallbackContext)callbackA callback that uses the DockerfileBuilder API to construct the Dockerfile.
options...*WithDockerfileBuilderOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithDockerfileBuilderOptions argument.

Stage*stringThe stage representing the image to be published in a multi-stage Dockerfile.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

Builds the specified container image from a Dockerfile generated by an asynchronous factory function.
WithDockerfileFactory(
contextPath string,
dockerfileFactory func(arg DockerfileFactoryContext) string,
options ...*WithDockerfileFactoryOptions,
) ContainerResource
contextPathstringPath to be used as the context for the container image build.
dockerfileFactoryfunc(arg DockerfileFactoryContext) stringcallbackAn asynchronous function that returns the Dockerfile content as a string.
options...*WithDockerfileFactoryOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithDockerfileFactoryOptions argument.

Stage*stringThe stage representing the image to be published in a multi-stage Dockerfile.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithEntrypointbuilder
Sets the Entrypoint for the container.
WithEntrypoint(entrypoint string) ContainerResource
entrypointstringThe new entrypoint for the container.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithImagebuilder
Allows overriding the image on a container.
WithImage(
image string,
options ...*WithImageOptions,
) ContainerResource
imagestringImage value.
options...*WithImageOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithImageOptions argument.

Tag*stringTag value.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithImagePullPolicybuilder
Sets the pull policy for the container resource.
WithImagePullPolicy(pullPolicy ImagePullPolicy) ContainerResource
pullPolicyImagePullPolicyThe pull policy behavior for the container resource.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithImageRegistrybuilder
Allows overriding the image registry on a container.
WithImageRegistry(registry string) ContainerResource
registrystringRegistry value.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithImageSHA256builder
Allows setting the image to a specific sha256 on a container.
WithImageSHA256(sha256 string) ContainerResource
sha256stringRegistry value.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithImageTagbuilder
Allows overriding the image tag on a container.
WithImageTag(tag string) ContainerResource
tagstringTag value.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithLifetimebuilder
Sets the lifetime behavior of the container resource.
WithLifetime(lifetime ContainerLifetime) ContainerResource
lifetimeContainerLifetimeThe lifetime behavior of the container resource. The default behavior is Session.
ContainerResource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithVolumebuilder
Adds a volume to a container resource.
WithVolume(
target string,
options ...*WithVolumeOptions,
) ContainerResource
targetstringThe mount path inside the container.
options...*WithVolumeOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithVolumeOptions argument.

Name*stringThe volume name. If null, an anonymous volume is created.
IsReadOnly*boolWhether the volume is read-only.
ContainerResource

The same resource builder handle for chaining.

Returns a handle; failures surface later via Err().