* add docker-compose sample * add Makefile * add README * small tweaks to README * Update README.md * updated based on feedback * small updates and reword * Add --components-path to work with 0.8.0 changes * Change port of redis to 6380 as 6379 would mostly likely be already in use because of the redis container that dapr spins up during "dapr init" * Add --components-path to the list of options * Change host port instead of container port in README * Change host port instead of container port Co-authored-by: Mark Fussell <mfussell@microsoft.com> Co-authored-by: Young Bu Park <youngp@microsoft.com> Co-authored-by: Pruthvidhar R Dhodda <60198385+pruthvidhodda@users.noreply.github.com> |
||
---|---|---|
.. | ||
components | ||
node | ||
python | ||
.gitignore | ||
README.md | ||
docker-compose.yml | ||
makefile |
README.md
Dapr with Docker-Compose
This sample demonstrates how to get Dapr running locally with Docker Compose. This uses the same applications as the 1.hello-world
sample, please review those docs for further information on the applicaiton architecture.
Prerequisites
Clone this repo using git clone https://github.com/dapr/samples.git
and go to the directory named /10.hello-docker-compose
Reviewing the Docker Compose Definition
Review the Docker Compose file ./docker-compose.yml below:
version: '3'
services:
############################
# Node app + Dapr sidecar
############################
nodeapp:
build: ./node
ports:
- "50002:50002"
depends_on:
- redis
- placement
networks:
- hello-dapr
nodeapp-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "nodeapp",
"-app-port", "3000",
"-placement-address", "placement:50006",
"-dapr-grpc-port", "50002",
"-components-path", "/components"]
volumes:
- "./components/:/components"
depends_on:
- nodeapp
network_mode: "service:nodeapp"
############################
# Python app + Dapr sidecar
############################
pythonapp:
build: ./python
depends_on:
- redis
- placement
networks:
- hello-dapr
pythonapp-dapr:
image: "daprio/daprd:edge"
command: ["./daprd",
"-app-id", "pythonapp",
"-placement-address", "placement:50006",
"-components-path", "/components"]
volumes:
- "./components/:/components"
depends_on:
- pythonapp
network_mode: "service:pythonapp"
############################
# Dapr placement service
############################
placement:
image: "daprio/dapr"
command: ["./placement", "-port", "50006"]
ports:
- "50006:50006"
networks:
- hello-dapr
############################
# Redis state store
############################
redis:
image: "redis:alpine"
ports:
- "6380:6379"
networks:
- hello-dapr
networks:
hello-dapr:
Services
This Docker Compose defintion has the following containerized services:
nodeapp
// The node appnodeapp-dapr
// The node app Dapr sidecarpythonapp
// The python apppythonapp-dapr
// The python app Dapr sidecarplacement
// Dapr's placement serviceredis
// Redis
Networking
Each of these services is deployed to the hello-dapr
Docker network and have their own IP on that network.
The nodeapp-dapr
and pythonapp-dapr
services are sharing a network namespace with their associated app service by using network_mode
.
This means that the app and the sidecars are able to communicate over their localhost interface.
Ports are still bound on the host machine, therefore, we need to ensure we avoid port conflicts.
Volumes
In order to get Dapr to load the redis statestore and pubsub components, you need to mount the
./components
directory to the default working directory. These component definitions have been modified
to talk to redis using a DNS name redis
rather than localhost. This resolves on the Docker network to
the IP of the container running redis.
Deploy the Docker Compose Definition
To deploy the above docker-compose.yml
you can run:
make run
If you want to change the Dapr Docker image used in the deployment, you can set the env var
DAPR_IMAGE
and runmake run
. This generates adocker-compose.override.yml
file using your custom image. If you want to revert to the default Dapr Docker image, you'll need to remove this file.
altentiavely, you can just use Docker Compose directly:
docker-compose up
Clean up
To tear down the Docker Compose deployment, you can run:
docker-compose down