Container service

Learn how to add a container to your Radius Application

Container provides an abstraction for a container workload that can be run on any platform Radius supports.

Resource format

resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'frontend'
  properties: {
    application: app.id
    container: {
      image: 'registry/container:tag'
      env:{
        DEPLOYMENT_ENV: {
          value: 'prod'
        }
        DB_CONNECTION: {
          value: db.listSecrets().connectionString
        }
      }
      ports: {
        http: {
          containerPort: 80
          protocol: 'TCP'
        }
      }
      volumes: {
        ephemeralVolume: {
          kind: 'ephemeral'
          mountPath: '/tmpfs'
          managedStore: 'memory'
        }
        persistentVolume: {
          kind: 'persistent'
          source: volume.id
        }
      }
      readinessProbe:{
        kind:'httpGet'
        containerPort:8080
        path: '/healthz'
        initialDelaySeconds:3
        failureThreshold:4
        periodSeconds:20
      }
      livenessProbe:{
        kind:'exec'
        command:'ls /tmp'
      }
      command: [
        '/bin/sh'
      ]
      args: [
        '-c'
        'while true; do echo hello; sleep 10;done'
      ]
      workingDir: '/app'
    }
    connections: {
      inventory: {
        source: db.id
      }
      azureStorage: {
        source: azureStorage
        iam: {
          kind: 'azure'
          roles: [
            'Storage Blob Data Contributor'
          ]
        }
      }
    }
    extensions: [
      {
        kind: 'daprSidecar'
        appId: 'frontend'
      }
      {
        kind:  'manualScaling'
        replicas: 5
      }
      {
        kind: 'kubernetesMetadata'
        labels: {
          'team.contact.name': 'frontend'
        }
      }
    ]
    runtimes: {
      kubernetes: {
        base: loadTextContent('base-container.yaml')
        pod: {
          containers: [
            {
              name: 'log-collector'
              image: 'ghcr.io/radius-project/fluent-bit:2.1.8'
            }
          ]
          hostNetwork: true
        }
      }
    }
  }
}

Top-level

KeyRequiredDescriptionExample
nameyThe name of your resource. See common values for more information.frontend
locationyThe location of your resource. See common values for more information.global
propertiesyProperties of the resource.See below

Properties

KeyRequiredDescriptionExample
applicationyThe ID of the application resource this container belongs to.app.id
containeryContainer configuration.See below
connectionsnList of connections to other resources.See below
extensionsnList of extensions on the container.See below
runtimesnRuntime specific configurations for the container.See below

Container

KeyRequiredDescriptionExample
imageyThe registry and image to download and run in your container. Follows the format <registry-hostname>:<port>/<image-name>:<tag> where registry hostname is optional and defaults to the Docker public registry, port is optional and defaults to 443, tag is optional and defaults to latest.ghcr.io/USERNAME/myimage:latest
envnA list of environment variables to be set for the container. Environment variables can either be of value or a reference to a Application.Core/SecretStore resource id in the format valueFrom.'ENV_VAR': { value: 'value' } or 'ENV_VAR': { valueFrom: { secretRef: { source: secret.id key: 'SECRET_KEY' } } }
commandnEntrypoint array. Overrides the container image’s ENTRYPOINT.['/bin/sh']
argsnArguments to the entrypoint. Overrides the container image’s CMD.['-c', 'while true; do echo hello; sleep 10;done']
imagePullPolicynHow to pull images. Defaults to the runtime’s default behavior. For Kubernetes behavior refer to https://kubernetes.io/docs/concepts/containers/images/#required-image-pull'Always'
workingDirnWorking directory for the container.'/app'
portsnPorts the container providesSee below.
readinessProbenReadiness probe configuration.See below.
livenessProbenLiveness probe configuration.See below.
volumesnVolumes to mount into the container.See below.

Ports

The ports offered by the container are defined in the ports section.

KeyRequiredDescriptionExample
nameyA name key for the port.http
containerPortyThe port the container exposes.80
protocolnThe protocol the container exposes. Options are ‘TCP’ and ‘UCP’.'TCP'

Volumes

KeyRequiredDescriptionExample
nameyA name key for the volume.tempstore
kindyThe type of volume, either ephemeral or persistent.ephemeral
mountPathyThe container path to mount the volume to.\tmp\mystore
managedStorey*The backing storage medium to use when kind is ’ephemeral’. Either disk or memory.memory
sourcey*A volume resource to mount when kind is ‘persistent’.myvolume.id
rbacnThe role-based access control level when kind is ‘persistent’. Allowed values are 'read' and 'write'. Defaults to ‘read’.'read'

Readiness probe

KeyRequiredDescriptionExample
kindyType of readiness check, httpGet or tcp or exec.httpGet
containerPortnUsed when kind is httpGet or tcp. The listening port number.8080
pathnUsed when kind is httpGet. The route to make the HTTP request on'/healthz'
commandnUsed when kind is exec. Command to execute to probe readiness'/healthz'
initialDelaySecondsnInitial delay in seconds before probing for readiness.10
failureThresholdnThreshold number of times the probe fails after which a failure would be reported.5
periodSecondsnInterval for the readiness probe in seconds.5

Liveness probe

KeyRequiredDescriptionExample
kindyType of liveness check, httpGet or tcp or exec.httpGet
containerPortnUsed when kind is httpGet or tcp. The listening port number.8080
pathnUsed when kind is httpGet. The route to make the HTTP request on'/healthz'
commandnUsed when kind is exec. Command to execute to probe liveness'/healthz'
initialDelaySecondsnInitial delay in seconds before probing for liveness.10
failureThresholdnThreshold number of times the probe fails after which a failure would be reported.5
periodSecondsnInterval for the liveness probe in seconds.5

Connections

KeyRequiredDescriptionExample
nameyA name key for the port.inventory
sourceyThe id of the resource the container is connecting to. For network connections to other services this is in the form '[scheme]://[serviceName]:[port]'db.id, 'http://inventory:8080'
iamnIdentity and access management (IAM) roles to set on the target resource.See below

IAM

Identity and access management (IAM) roles to set on the target resource.

KeyRequiredDescriptionExample
kindyType of IAM role. Only azure supported today'azure'
rolesyThe list IAM roles to set on the target resource.'Owner'

Extensions

Extensions define additional capabilities and configuration for a container.

KeyRequiredDescriptionExample
kindyThe kind of extension being used.kubernetesMetadataextension

Additional properties are available and required depending on the ‘kind’ of the extension.

kubernetesMetadata

The Kubernetes Metadata extension enables you set and cascade Kubernetes metadata such as labels and Annotations on all the Kubernetes resources defined with in your Radius Application. For examples refer to the extension overview page.

Properties
KeyRequiredDescriptionExample
kindyThe kind of extension being used. Must be ‘kubernetesMetadata’kubernetesMetadata
labelsnThe Kubernetes labels to be set on the application and its resourcesSee below
annotationsnThe Kubernetes annotations to set on your application and its resourcesSee below
labels
KeyRequiredDescriptionExample
user defined label keyyThe key and value of the label to be set on the application and its resources.'team.name': 'frontend'
annotations
KeyRequiredDescriptionExample
user defined annotation keyyThe key and value of the annotation to be set on the application and its resources.'app.io/port': '8081'

daprSidecar

The daprSidecar extensions adds and configures a Dapr sidecar to your application.

Properties
PropertyRequiredDescriptionExample
kindyThe kind of extension.daprSidecar
appIdnThe appId of the Dapr sidecar.backend
appPortnThe port your service exposes to Dapr3500
confignThe configuration to use for the Dapr sidecar

manualScaling

The manualScaling extension configures the number of replicas of a compute instance (such as a container) to run.

Properties
PropertyRequiredDescriptionExample
kindyThe kind of extension.manualScaling
replicasYThe number of replicas to run5

Runtimes

KeyRequiredDescriptionExample
kubernetesnKubernetes specific configuration for the container.See below
acinAzure Container Instances specific configuration for the container.See below

Kubernetes

KeyRequiredDescriptionExample
basenThe base Kubernetes resource manifest on top of which Radius specified properties will be applied. Supported resource types are documented here.loadTextContent('manifest/base-container.yaml')
podnThe pod specifications to apply to the Kubernetes resource created by Radius. Any field defined on PodSpec can be set here.topologySpreadConstraints

ACI

KeyRequiredDescriptionExample
gatewayIDnThe gateway resource ID that provides L7 traffic for the container.'myGatewayId'