入门指南: 使用 Docker 在自托管模式下运行 Dapr

This article provides guidance on running Dapr with Docker on a Windows/Linux/macOS machine or VM.

Initialize Dapr environment

To initialize the Dapr control-plane containers and create a default configuration file, run:

Run both app and sidecar as a process

The can be used to launch a Dapr sidecar along with your application:

This command will launch both the daprd sidecar binary and run dotnet run, launching your application.

Alternately, if you are running Dapr in a Docker container and your app as a process on the host machine, then you need to configure Docker to use the host network so that Dapr and the app can share a localhost network interface.

Note

The host networking driver for Docker is only supported on Linux hosts.

If you are running your Docker daemon on a Linux host, you can run the following to launch Dapr:

Run both app and Dapr in a single Docker container

不建议在同一容器内运行 Dapr 运行时和应用程序。 但是,对于本地开发的场景,可以这样做。

为了做到这一点,你需要编写一个Docker文件,安装Dapr运行时、Dapr CLI和你的应用代码。 然后,您可以使用 Dapr CLI 调用Dapr 运行时和您的应用代码。

下面是实现这一目标的Docker文件的例子。

  1. FROM python:3.7.1
  2. # Install dapr CLI
  3. RUN wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
  4. # Install daprd
  5. ARG DAPR_BUILD_DIR
  6. COPY $DAPR_BUILD_DIR /opt/dapr
  7. # Install your app
  8. WORKDIR /app
  9. COPY python .
  10. RUN pip install requests
  11. CMD ["run", "--app-id", "nodeapp", "--app-port", "3000", "node", "app.js"]

请记住,如果Dapr需要与其他组件通信,即: Redis,这些也需要让它访问。 Redis,这些也需要让它访问。

在 Docker 网络运行

If you have multiple instances of Dapr running in Docker containers and want them to be able to communicate with each other i.e. for service invocation, then you’ll need to create a shared Docker network and make sure those Dapr containers are attached to it.

您可以使用以下方法创建一个简单的Docker网络:

  1. docker run --net=my-dapr-network ...

每个容器将在该网络上获得一个唯一的IP,并能与该网络上的其他容器进行通信。

can be used to define multi-container application configurations. 如果您希望在没有Kubernetes的情况下,在本地使用Dapr sidecars运行多个应用程序,那么建议使用Docker Compose定义()。

Docker Compose的语法和工具超出了本文的范围,但是,建议你参考官方Docker文档了解更多细节。

为了使用Dapr和Docker Compose运行您的应用程序,您需要在您的docker-compose.yml中定义sidecar模式。 例如:

对于那些在Linux主机上运行Docker守护进程的用户,如果需要的话,还可以使用network_mode: host来利用主机联网。

要进一步了解如何使用 Docker Compose 运行 Dapr,请参见 。

在 Kubernetes 运行

If your deployment target is Kubernetes please use Dapr’s first-class integration. Refer to the .

Docker images

上,每个 Dapr 组件都有已发布的 Docker 镜像。

Tags

Linux/amd64

  • latest:最新版本, 用于开发目的。
  • edge: 最新的edge构建(master)。
  • major.minor.patch: 发布版本。
  • major.patch-rc.iteration: 候选发布。

Linux/arm/v7

  • latest-arm:最新的ARM版本, 用于开发目的。
  • edge-arm: ARM的最新的edge构建(master)。
  • : ARM的发布版本。
  • major.patch-rc.iteration: ARM的候选发布。