-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose_swarm.yaml
More file actions
33 lines (29 loc) · 2.14 KB
/
docker-compose_swarm.yaml
File metadata and controls
33 lines (29 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
services:
# ATTENTION: here we use a replica set with docker SWARM (so dont use docker compose for starting it!)
# to make both available you must use `docker stack deploy -c docker-compose.yaml myswarm`
# runs only if a remote worker is attatched!
fastapi_swarm: # this is the SWARM!!!
image: 192.168.1.1:5000/fastapi_arm:latest # this will be eval on build time so 192.168.1.1 must be reachable from the machine (here we use the WIN IP but the portproxy will forward it accordingly)
hostname: "swarm.{{.Task.Slot}}" # this replaces the containerID with a meaningfull name
deploy:
# replicas: 2 # this deploys 2 replicas of this image in docker swarm
mode: global # global means it deploy one container on all workers in the swarm (and on the manager node also)
placement:
constraints:
- node.role == worker # tells Swarm to run one instance of the service on every worker node, excluding the manager
# to define by tags which nodes should be used (you must tag them before with `docker node update --label-add target=true <MANAGER_NODE_ID>`)
# - node.labels.target == true
restart_policy:
condition: on-failure
endpoint_mode: dnsrr # This tells Docker Swarm to use DNS Round Robin, which will return each container's IP address as separate entries. Then NGINX will have multiple endpoints to distribute requests across.
# Exposing Ports is NOT needed with SWARM: internal connectivity works automatically
networks:
swarm-net:
aliases:
- fastapi_swarm
networks:
swarm-net: # this will create an overlay network used by docker swarm
# external: true # if you wnat to connect to an existing overlay network
name: swarm-net # with this the name of the network is setted
driver: overlay # for all swarm "overlay" network is recommended (mandatory if multiple node setup)
attachable: true # <-- important! Docker allows containers (and the Compose process) to attach to the overlay network, preventing the PermissionDenied error.