Skip to content

Commit e006f69

Browse files
jjcollingeyoungbuparkOri Zohar
authored
WIP: Add Dapr with Docker docs (dapr#598)
* add howto for dapr with docker * updated README * updated README * update docs to align with template * expand intro * add link to section * fix typo * align headers * Style and tone updates Removing first person phrasing and additional minor changes to style and tone. * add not about host network mode * added mount to run cmd Co-authored-by: Young Bu Park <youngp@microsoft.com> Co-authored-by: Ori Zohar <orzohar@microsoft.com>
1 parent d52604e commit e006f69

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

howto/run-with-docker/README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Run with Docker
2+
This article provides guidance on running Dapr with Docker outside of Kubernetes. There are a number of different configurations in which you may wish to run Dapr with Docker that are documented below.
3+
4+
## Prerequisites
5+
- [Docker](https://docs.docker.com/get-docker/)
6+
- [Docker-Compose](https://docs.docker.com/compose/install/) (optional)
7+
8+
## Select a Docker image
9+
Dapr provides a number of prebuilt Docker images for different components, you should select the relevant image for your desired binary, architecture, and tag/version.
10+
11+
### Images
12+
There are published Docker images for each of the Dapr components available on [Docker Hub](https://hub.docker.com/u/daprio).
13+
- [daprio/dapr](https://hub.docker.com/r/daprio/dapr) (contains all Dapr binaries)
14+
- [daprio/daprd](https://hub.docker.com/r/daprio/daprd)
15+
- [daprio/placement](https://hub.docker.com/r/daprio/placement)
16+
- [daprio/sentry](https://hub.docker.com/r/daprio/sentry)
17+
- [daprio/dapr-dev](https://hub.docker.com/r/daprio/dapr-dev)
18+
19+
### Tags
20+
#### Linux/amd64
21+
- `latest`: The latest release version, **ONLY** use for development purposes.
22+
- `edge`: The latest edge build (master).
23+
- `major.minor.patch`: A release version.
24+
- `major.minor.patch-rc.iteration`: A release candidate.
25+
#### Linux/arm/v7
26+
- `latest-arm`: The latest release version for ARM, **ONLY** use for development purposes.
27+
- `edge-arm`: The latest edge build for ARM (master).
28+
- `major.minor.patch-arm`: A release version for ARM.
29+
- `major.minor.patch-rc.iteration-arm`: A release candidate for ARM.
30+
31+
## Run Dapr in a Docker container with an app as a process
32+
> For development purposes ONLY
33+
34+
If you are running Dapr in a Docker container and your app as a process on the host machine, then you need to configure
35+
Docker to use the host network so that Dapr and the app can share a localhost network interface. Unfortunately, the host networking driver for Docker is only supported on Linux hosts.
36+
If you are running your Docker daemon on a Linux host, you should be able to run the following to launch Dapr.
37+
```shell
38+
docker run --net="host" --mount type=bind,source="$(pwd)"/components,target=/components daprio/daprd:edge ./daprd -app-id <my-app-id> -app-port <my-app-port>
39+
```
40+
Then you can run your app on the host and they should connect over the localhost network interface.
41+
42+
However, if you are not running your Docker daemon on a Linux host, it is recommended you follow the steps below to run
43+
both your app and the [Dapr runtime in Docker containers using Docker Compose](#run-dapr-in-a-docker-container-using-docker-compose).
44+
45+
## Run Dapr and an app in a single Docker container
46+
> For development purposes ONLY
47+
48+
It is not recommended to run both the Dapr runtime and an application inside the same container. However, it is possible to do so for local development scenarios.
49+
In order to do this, you'll need to write a Dockerfile that installs the Dapr runtime, Dapr CLI and your app code.
50+
You can then invoke both the Dapr runtime and your app code using the Dapr CLI.
51+
52+
Below is an example of a Dockerfile which achieves this:
53+
```
54+
FROM python:3.7.1
55+
# Install dapr CLI
56+
RUN wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
57+
58+
# Install daprd
59+
ARG DAPR_BUILD_DIR
60+
COPY $DAPR_BUILD_DIR /opt/dapr
61+
ENV PATH="/opt/dapr/:${PATH}"
62+
63+
# Install your app
64+
WORKDIR /app
65+
COPY python .
66+
RUN pip install requests
67+
ENTRYPOINT ["dapr"]
68+
CMD ["run", "--app-id", "nodeapp", "--app-port", "3000", "node", "app.js"]
69+
```
70+
71+
Remember that if Dapr needs to communicate with other components i.e. Redis, these also need to
72+
be made accessible to it.
73+
74+
## Run Dapr in a Docker container on a Docker network
75+
If you have multiple instances of Dapr running in Docker containers and want them to be able to
76+
communicate with each other i.e. for service invocation, then you'll need to create a shared Docker network
77+
and make sure those Dapr containers are attached to it.
78+
79+
You can create a simple Docker network using
80+
```
81+
docker network create my-dapr-network
82+
```
83+
When running your Docker containers, you can attach them to the network using
84+
```
85+
docker run --net=my-dapr-network ...
86+
```
87+
Each container will receive a unique IP on that network and be able to communicate with other containers on that network.
88+
89+
## Run Dapr in a Docker container using Docker-Compose
90+
[Docker Compose](https://docs.docker.com/compose/) can be used to define multi-container application
91+
configurations. If you wish to run multiple apps with Dapr sidecars locally without Kubernetes then it is recommended to use a Docker Compose definition (`docker-compose.yml`).
92+
93+
The syntax and tooling of Docker Compose is outside the scope of this article, however, it is recommended you refer to the [offical Docker documentation](https://docs.docker.com/compose/) for further details.
94+
95+
In order to run your applications using Dapr and Docker Compose you'll need to define the sidecar pattern in your `docker-compose.yml`. For example:
96+
97+
```yaml
98+
version: '3'
99+
services:
100+
nodeapp:
101+
build: ./node
102+
ports:
103+
- "50001:50001" # Dapr instances communicate over gRPC so we need to expose the gRPC port
104+
depends_on:
105+
- redis
106+
- placement
107+
networks:
108+
- hello-dapr
109+
nodeapp-dapr:
110+
image: "daprio/daprd:edge"
111+
command: [
112+
"./daprd",
113+
"-app-id", "nodeapp",
114+
"-app-port", "3000",
115+
"-placement-address", "placement:50006" # Dapr's placement service can be reach via the docker DNS entry
116+
]
117+
volumes:
118+
- "./components/:/components" # Mount our components folder for the runtime to use
119+
depends_on:
120+
- nodeapp
121+
network_mode: "service:nodeapp" # Attach the nodeapp-dapr service to the nodeapp network namespace
122+
123+
... # Deploy other daprized services and components (i.e. Redis)
124+
125+
placement:
126+
image: "daprio/dapr"
127+
command: ["./placement", "-port", "50006"]
128+
ports:
129+
- "50006:50006"
130+
networks:
131+
- hello-dapr
132+
```
133+
134+
> For those running the Docker daemon on a Linux host, you can also use `network_mode: host` to leverage host networking if needed.
135+
136+
To further learn how to run Dapr with Docker Compose, see the [Docker-Compose Sample](https://github.com/dapr/samples/10.hello-docker-compose).
137+
138+
## Run Dapr in a Docker container on Kubernetes
139+
If your deployment target is Kubernetes then you're probably better of running your applicaiton and Dapr sidecars directly on
140+
a Kubernetes platform. Running Dapr on Kubernetes is a first class experience and is documented separately. Please refer to the
141+
following references:
142+
- [Setup Dapr on a Kubernetes cluster](https://github.com/dapr/docs/blob/ea5b1918778a47555dbdccff0ed6c5b987ed10cf/getting-started/environment-setup.md#installing-dapr-on-a-kubernetes-cluster)
143+
- [Hello Kubernetes Sample](https://github.com/dapr/samples/tree/master/2.hello-kubernetes)
144+
- [Configuring the Dapr sidecar on Kubernetes](https://github.com/dapr/docs/blob/c88d247a2611d6824d41bb5b6adfeb38152dbbc6/howto/configure-k8s/README.md)
145+
- [Running Dapr in Kubernetes mode](https://github.com/dapr/docs/blob/a7668cab5e16d12f364a42d2fe7d75933c6398e9/overview/README.md#running-dapr-in-kubernetes-mode)
146+
147+
## Related links
148+
- [Docker-Compose Sample](https://github.com/dapr/samples/10.hello-docker-compose)

0 commit comments

Comments
 (0)