Skip to content

Stack Solution

cat docker-compose.yml
services:
producteur:
image: alpine:3.17
command: ["/bin/sh","-c","while true ; do echo `date` : `hostname` >> /mnt/index.html ; sleep 60 ; done"]
volumes:
- "nfs_web:/mnt"
networks:
- web
deploy:
mode: global
consommateur:
image: nginx:1.19-alpine
volumes:
- "nfs_web:/usr/share/nginx/html"
ports:
- "80:80"
networks:
- web
deploy:
replicas: 4
networks:
web:
volumes:
nfs_web:
driver_opts:
type: "nfs"
o: "addr=192.168.1.5"
device: ":/home/shares/user11"

Créer la stack

docker stack deploy -c docker-compose.yml mystack
Since --detach=false was not specified, tasks will be created in the background.
In a future release, --detach=false will become the default.
Creating network mystack_web
Creating service mystack_producteur
Creating service mystack_consommateur

Lister la stack

docker stack ls
NAME SERVICES
mystack 2

Lister les tasks

docker stack ps mystack
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
0e3mn4uk26mi mystack_consommateur.1 nginx:1.19-alpine host112 Running Running about a minute ago
qso698588kms mystack_consommateur.2 nginx:1.19-alpine host113 Running Running about a minute ago
qmepd1r8g62e mystack_consommateur.3 nginx:1.19-alpine host112 Running Running about a minute ago
6zpdm43cuzjp mystack_consommateur.4 nginx:1.19-alpine host113 Running Running about a minute ago
nyc3l8tjvhl1 mystack_producteur.lbg3wl9lbwlhfrr4euz2ixgpi alpine:3.17 host112 Running Running about a minute ago
c61d9aot51m3 mystack_producteur.sgd84a7jb5iv4ar6m87zn4znh alpine:3.17 host113 Running Running about a minute ago