Dapr 的命令行工具 .
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.
On default, during initialization the Dapr CLI will install the Dapr binaries as well as setup a developer environment to help you get started easily with Dapr. This environment uses Docker containers, therefore Docker needs to be installed. If you prefer to run Dapr without this environment and no dependency on Docker, after installation of the CLI make sure to follow the instructions to initialize Dapr using slim init.
Note, if you are a new user, it is strongly recommended to install Docker and use the regular init command.
Note: On Windows, Docker must be running in Linux Containers mode
Windows
Install the latest windows Dapr CLI to $Env:SystemDrive\dapr and add this directory to User PATH environment variable. Use -DaprRoot [path] to change the default installation directory
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/bashMacOS
Install the latest darwin Dapr CLI to /usr/local/bin
curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | /bin/bashEach release of Dapr CLI includes various OSes and architectures. These binary versions can be manually downloaded and installed.
/usr/local/binc:\dapr and add this directory to your path, by editing your system environment variable.Install windows Dapr CLI using MSI package.
dapr.msi to install Dapr CLI on your systemNOTE: The default installation directory is set to
$Env:SystemDrive\daprand can be modified at the time of installation.
In self-hosted mode, dapr can be initialized using the CLI with the placement, scheduler, redis, and zipkin containers enabled by default(recommended) or without them which also does not require docker to be available in the environment.
(Prerequisite: Docker is available in the environment - recommended)
Use the init command to initialize Dapr. On init, multiple default configuration files and containers are installed along with the dapr runtime binary. Dapr runtime binary is installed under $HOME/.dapr/bin for Mac, Linux and %USERPROFILE%.dapr\bin for Windows.
dapr initFor Linux users, if you run your docker cmds with sudo, you need to use "sudo dapr init"
Output should look like so:
⌛ Making the jump to hyperspace...
✅ Downloaded binaries and completed components set up.
ℹ️ daprd binary has been installed to $HOME/.dapr/bin.
ℹ️ dapr_placement container is running.
ℹ️ dapr_scheduler container is running.
ℹ️ dapr_redis container is running.
ℹ️ dapr_zipkin container is running.
ℹ️ Use `docker ps` to check running containers.
✅ Success! Dapr is up and running. To get started, go here: https://docs.dapr.io/getting-startedNote: To see that Dapr has been installed successfully, from a command prompt run the
docker pscommand and check that thedaprio/dapr:latest,dapr_redisanddapr_zipkincontainer images are all running.
This step creates the following defaults:
dapr run unless the --resources-path (--components-path is deprecated and will be removed in future releases) option is provided. For Linux/MacOS, the default components folder path is $HOME/.dapr/components and for Windows it is %USERPROFILE%\.dapr\components.pubsub.yaml and statestore.yaml.$HOME/.dapr/config.yaml for Linux/MacOS or for Windows at %USERPROFILE%\.dapr\config.yaml to enable tracing on dapr init call. Can be overridden with the --config flag on dapr run.Alternatively to the above, to have the CLI not install any default configuration files or run Docker containers, use the --slim flag with the init command. Only Dapr binaries will be installed.
dapr init --slimOutput should look like so:
⌛ Making the jump to hyperspace...
✅ Downloaded binaries and completed components set up.
ℹ️ daprd binary has been installed to $HOME/.dapr/bin.
ℹ️ placement binary has been installed.
ℹ️ scheduler binary has been installed.
✅ Success! Dapr is up and running. To get started, go here: https://docs.dapr.io/getting-startedNote: When initializing Dapr with the
--slimflag only the Dapr runtime, placement, and scheduler service binaries are installed. An empty default components folder is created with no default configuration files. Duringdapr runuser should use--resources-path(--components-pathis deprecated and will be removed in future releases) to point to a components directory with custom configurations files or alternatively place these files in the default directory. For Linux/MacOS, the default components directory path is$HOME/.dapr/componentsand for Windows it is%USERPROFILE%\.dapr\components.
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 v1.0.0 runtime
dapr init --runtime-version 1.0.0
# Check the versions of CLI and runtime
dapr --version
CLI version: v1.0.0
Runtime version: v1.0.0You can install Dapr Runtime using mariner images using the --image-variant flag.
# Installing Dapr with Mariner images
dapr init --image-variant marinerYou can install Dapr runtime by pulling docker images from a given private registry uri by using --image-registry flag.
Note: This command expects that images have been hosted like example.io//dapr/dapr:, example.io//dapr/3rdparty/redis:, example.io//dapr/3rdparty/zipkin:
# Example of pulling images from a private registry.
dapr init --image-registry example.io/You can install Dapr runtime with a custom scheduler host and port by using --scheduler-override-broadcast-host-port flag.
dapr init --scheduler-override-broadcast-host-port 192.168.42.42:50006Note: The default host is
localhost.
You can install Dapr runtime in airgap (offline) environment using a pre-downloaded installer bundle. You need to download the archived bundle for your OS beforehand (e.g., daprbundle_linux_amd64.tar.gz,) and unpack it. Thereafter use the local Dapr CLI binary in the bundle with --from-dir flag in the init command to point to the extracted bundle location to initialize Dapr.
Move to the bundle directory and run the following command:
# Initializing dapr in airgap environment
./dapr init --from-dir .For windows, use
.\dapr.exeto point to the local Dapr CLI binary.
If you are not running the above command from the bundle directory, provide the full path to bundle directory as input. For example, assuming the bundle directory path is $HOME/daprbundle, run
$HOME/daprbundle/dapr init --from-dir $HOME/daprbundleto have the same behavior.
Note: Dapr Installer bundle just contains the placement and scheduler containers apart from the binaries and so
zipkinandredisare not enabled by default. You can pull the images locally either from network or private registry and run as follows:
docker run --name "dapr_zipkin" --restart always -d -p 9411:9411 openzipkin/zipkin
docker run --name "dapr_redis" --restart always -d -p 6379:6379 redisAlternatively to the above, you can also have slim installation as well to install dapr without running any Docker containers in airgap mode.
./dapr init --slim --from-dir .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-networkNote: When installed to a specific Docker network, you will need to add the
--placement-host-addressarguments todapr runcommands run in any containers within that network. The format of--placement-host-addressargument is either `` or:. If the port is omitted, the default port6050for Windows and50005for Linux/MacOS applies.
Note: When installed to a specific Docker network, you will need to add the
--scheduler-host-addressarguments todapr runcommands run in any containers within that network. The format of--scheduler-host-addressargument is either `` or:. If the port is omitted, the default port6060for Windows and50006for Linux/MacOS applies.
You can install the Dapr runtime using a specific container runtime
environment such as Docker or Podman by passing along the
--container-runtime argument:
# Install Dapr with Podman
$ dapr init --container-runtime podmanNote: The default container runtime is Docker.
To install the Dapr CLI in a dev container or GitHub Codespace, add the following to your devcontainer.json file:
"features": {
"ghcr.io/dapr/cli/dapr-cli:0": {}
}Restart your dev container or GitHub Codespace and run dapr init to initialize Dapr.
For more details, see the docs for dev containers with Visual Studio Code and GitHub Codespaces.
Uninstalling will remove daprd binary along with the placement and scheduler containers (if installed with Docker or the placement and scheduler binaries if not).
dapr uninstallFor Linux users, if you run your docker cmds with sudo, you need to use "sudo dapr uninstall" to remove the containers.
The command above won't remove the redis or zipkin containers by default in case you were using it for other purposes. It will also not remove the default dapr folder that was created on dapr init. To remove all the containers (placement, scheduler, redis, zipkin) and also the default dapr folder created on init run:
dapr uninstall --allThe above command can also be run when Dapr has been installed in a non-docker environment, it will only remove the installed binaries and the default dapr folder in that case.
NB: The
dapr uninstallcommand will always try to remove the placement and scheduler binaries/services and will throw an error is not able to.
**You should always run a dapr uninstall before running another `d
暂无开放 Issues,或尚未同步最近议题。