ContainerResource class represents a Docker container that can be run as part of your distributed application. It provides extensive configuration options for images, volumes, networking, and runtime behavior.
Class Definition
Constructor
Unique name for the container resource. Used for service discovery and references.
Optional custom entrypoint that overrides the container image’s default ENTRYPOINT.
Properties
Gets or sets the container entrypoint.
null means use the default from the image.Creating Containers
Basic Container
From Dockerfile
Image Configuration
Image Methods
Sets the container image and optional tag.Parameters:
image- Image name (e.g., “redis”, “postgres”)tag- Optional tag (defaults to “latest”)
Changes the image tag without modifying the image name.Example:
Sets the container registry to pull the image from.Example:
Pins the image to a specific SHA256 digest for immutability.Example:
Storage Configuration
Volumes
Volumes are managed by Docker and persist data between container restarts.Adds a Docker volume to the container.Parameters:
name- Volume name (null creates anonymous volume)target- Mount path inside containerisReadOnly- Whether the volume is read-only
Bind Mounts
Bind mounts map host directories/files into the container.Mounts a host directory or file into the container.Parameters:
source- Host path (relative to app host directory or absolute)target- Mount path inside containerisReadOnly- Whether the mount is read-only
Relative paths are resolved from the app host project directory (
builder.AppHostDirectory).Runtime Configuration
Entrypoint and Command
Container Lifetime
Sets the container lifetime behavior.Values:
ContainerLifetime.Session- Container is removed when app stops (default)ContainerLifetime.Persistent- Container persists across app restarts
Image Pull Policy
Controls when the container runtime pulls the image.Values:
ImagePullPolicy.Always- Always pull the imageImagePullPolicy.IfNotPresent- Pull only if not cached locallyImagePullPolicy.Never- Never pull, fail if not cached
Container Runtime Arguments
Pass arguments directly to the container runtime (docker run or podman run).Adds arguments to the container runtime command (not the container entrypoint).Parameters:
args- String arguments passed to docker/podman run
Networking
Endpoints
Complete Examples
PostgreSQL Database
Production PostgreSQL
Nginx Reverse Proxy
Custom Nginx
Custom Application Container
Full Configuration
Related APIs
- IResourceBuilder - Builder configuration methods
- Hosting Extensions - Adding resources to applications
- IResource - Resource interfaces and contracts