The Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernetes cluster, provides debugging support, launches and manages Dapr instances.
- Install Docker
Note: On Windows, Docker must be running in Linux Containers mode
Windows
Install the latest windows Dapr CLI to c:\dapr
and add this directory to User PATH environment variable.
powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"
Linux
Install the latest linux Dapr CLI to /usr/local/bin
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
MacOS
Install the latest darwin Dapr CLI to /usr/local/bin
curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | /bin/bash
Each release of Dapr CLI includes various OSes and architectures. These binary versions can be manually downloaded and installed.
- Download the Dapr CLI
- Unpack it (e.g. dapr_linux_amd64.tar.gz, dapr_windows_amd64.zip)
- Move it to your desired location.
- For Linux/MacOS -
/usr/local/bin
- For Windows, create a directory and add this to your System PATH. For example create a directory called
c:\dapr
and add this directory to your path, by editing your system environment variable.
- For Linux/MacOS -
$ dapr init
⌛ Making the jump to hyperspace...
↗ Downloading binaries and setting up components...
✅ Success! Dapr is up and running
Note: To see that Dapr has been installed successful, from a command prompt run the
docker ps
command and check that thedaprio/dapr:latest
andredis
container images are both running.
You can install or upgrade to a specific version of the Dapr runtime using dapr init --runtime-version
. You can find the list of versions in Dapr Release.
# Install v0.1.0 runtime
$ dapr init --runtime-version 0.1.0
# Check the versions of CLI and runtime
$ dapr --version
CLI version: v0.1.0
Runtime version: v0.1.0
You can install the Dapr runtime to a specific Docker network in order to isolate it from the local machine (e.g. to use Dapr from within a Docker container).
# Create Docker network
$ docker network create dapr-network
# Install Dapr to the network
$ dapr init --network dapr-network
Note: When installed to a specific Docker network, you will need to add the
--redis-host
and--placement-host
arguments todapr run
commands run in any containers within that network.
Uninstalling will remove the placement container.
$ dapr uninstall
The command above won't remove the redis container by default in case you were using it for other purposes. To remove both the placement and redis container:
$ dapr uninstall --all
You should always run a dapr uninstall
before running another dapr init
.
If previously installed to a specific Docker network, Dapr can be uninstalled with the --network
argument:
$ dapr uninstall --network dapr-network
The init command will install the latest stable version of Dapr on your cluster. For more advanced use cases, use our Helm Chart.
Please note, that using the CLI does not support non-default namespaces.
If you need a non-default namespace, please use Helm.
$ dapr init --kubernetes
⌛ Making the jump to hyperspace...
ℹ️ Note: this installation is recommended for testing purposes. For production environments, please use Helm
✅ Deploying the Dapr Operator to your cluster...
✅ Success! Dapr has been installed. To verify, run 'kubectl get pods -w' in your terminal
To remove Dapr from your Kubernetes cluster, use the uninstall
command with --kubernetes
Note: this won't remove Dapr installations that were deployed using Helm.
$ dapr uninstall --kubernetes
The Dapr CLI lets you debug easily by launching both Dapr and your app. Logs from both the Dapr Runtime and your app will be displayed in real time!
Example of launching Dapr with a node app:
$ dapr run --app-id nodeapp node app.js
Example of launching Dapr with a node app listening on port 3000:
$ dapr run --app-id nodeapp --app-port 3000 node app.js
Example of launching Dapr on HTTP port 6000:
$ dapr run --app-id nodeapp --app-port 3000 --port 6000 node app.js
Example of launching Dapr on gRPC port 50002:
$ dapr run --app-id nodeapp --app-port 3000 --grpc-port 50002 node app.js
Example of launching Dapr within a specific Docker network:
$ dapr run --app-id nodeapp --redis-host dapr_redis --placement-host dapr_placement node app.js
Note: When in a specific Docker network, the Redis and placement service containers are given specific network aliases,
dapr_redis
anddapr_placement
, respectively.
If your app uses gRPC instead of HTTP to receive Dapr events, run the CLI with the following command:
dapr run --app-id nodeapp --protocol grpc --app-port 6000 node app.js
The example above assumed your app port is 6000.
To use pub-sub with your app, make sure that your app has a POST
HTTP endpoint with some name, say myevent
.
This sample assumes your app is listening on port 3000.
Launch Dapr and your app:
$ dapr run --app-id nodeapp --app-port 3000 node app.js
Publish a message:
$ dapr publish --topic myevent
Publish a message with a payload:
- Linux/Mac
$ dapr publish --topic myevent --payload '{ "name": "yoda" }'
- Windows
C:> dapr publish --topic myevent --payload "{ \"name\": \"yoda\" }"
To test your endpoints with Dapr, simply expose any POST
HTTP endpoint.
For this sample, we'll assume a node app listening on port 3000 with a /mymethod
endpoint.
Launch Dapr and your app:
$ dapr run --app-id nodeapp --app-port 3000 node app.js
Invoke your app:
$ dapr invoke --app-id nodeapp --method mymethod
To list all Dapr instances running on your machine:
$ dapr list
To list all Dapr instances running in a Kubernetes cluster:
$ dapr list --kubernetes
To check if Mutual TLS is enabled in your Kubernetes cluster:
$ dapr mtls --kubernetes
To list all Dapr components on Kubernetes:
$ dapr components --kubernetes
To list all Dapr configurations on Kubernetes:
$ dapr configurations --kubernetes
Use dapr list
to get a list of all running instances.
To stop a Dapr app on your machine:
$ dapr stop --app-id myAppID
In order to enable profiling, use the enable-profiling
flag:
$ dapr run --app-id nodeapp --app-port 3000 node app.js --enable-profiling
Dapr will automatically assign a profile port for you.
If you want to manually assign a profiling port, use the profile-port
flag:
$ dapr run --app-id nodeapp --app-port 3000 node app.js --enable-profiling --profile-port 7777
In order to set the Dapr runtime log verbosity level, use the log-level
flag:
$ dapr run --app-id nodeapp --app-port 3000 node app.js --log-level debug
This sets the Dapr log level to debug
.
The default is info
.
You can run Dapr's sidecar only (daprd
) by omitting the application's command in the end:
$ dapr run --app-id myapp --port 3005 --grpc-port 50001
See the Reference Guide for more information about individual Dapr commands.
See the Development Guide to get started with building and developing.
This project has adopted the Microsoft Open Source Code of conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.