How-To: Add a Dapr sidecar to a container

Learn how to add a Dapr sidecar to a Radius container

This how-to guide will provide an overview of how to:

Prerequisites

Step 1: Start with a container

Begin by creating a file named app.bicep with a Radius container:

import radius as radius

@description('The ID of your Radius Application. Automatically injected by the rad CLI.')
param application string

resource demo 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'demo'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
    }
  }
}

Step 2: Add a Dapr sidecar extension

Now add the Dapr sidecar extension, which enabled Dapr and adds a Dapr sidecar:

resource demo 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'demo'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
    }
    extensions: [
      {
        kind: 'daprSidecar'
        appId: 'demo'
        appPort: 3000
      }
    ]
  }
}

Step 3: Deploy the app

Deploy your application:

rad deploy ./app.bicep -a demo

Your console output should look similar to:

Building ./app.bicep...
Deploying template './app.bicep' for application 'demo' and environment 'default' from workspace 'default'...
Deployment In Progress... 
...                  demo           Applications.Core/containers
Deployment Complete
Resources:
   demo           Applications.Core/containers

Step 4: Verify the Dapr sidecar

Run dapr list -k to list all Dapr pods in your Kubernetes cluster:

dapr list -k

The console output should look similar to:

NAMESPACE      APP ID    APP PORT   AGE  CREATED              
default-demo   demo      3000       29s  2023-11-30 21:52.59

Done

You’ve successfully deployed a Radius container with a Dapr sidecar! You can now interact with Dapr building blocks and the Dapr API from your container.

Cleanup

Run the following command to delete your app and container:

rad app delete -a demo

Further reading