Exaple 3:
-----------
vi example3.yml
version: "3.8"
services:
web_nginx:
image: nginx
ports:
"8080:80"
deploy:
mode: replicated
replicas: 4
placement:
constraints:
"node.role!=manager"
preferences:
spread: node.labels.datacenter
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
busybox_utility:
image: radial/busyboxplus:curl
command: /bin/sh -c "while true; do sleep 10; done"
docker stack deploy -c example3.yml app3
docker stack ls
docker stack services app3
docker stack ps app3
docker stack rm app3
Example 4:
--------------
vi example4.yml
version: "3.8"
services:
web_nginx:
image: nginx
ports:
"8080:80"
deploy:
mode: replicated
replicas: 4
placement:
constraints:
"node.role!=manager"
preferences:
spread: node.labels.datacenter
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
volumes:
type: volume
source: myvolume
target: /data
busybox_utility:
image: radial/busyboxplus:curl
command: /bin/sh -c "while true; do sleep 10; done"
volumes:
myvolume:
docker stack deploy -c example4.yml app4
docker volume ls
docker stack ls
docker stack ps app4
docker stack rm app4
Example 5:
-------------
vi example5.yml
example5:
vi exampe5.yml
version: "3.8"
services:
web_nginx:
image: nginx
ports:
"8080:80"
deploy:
mode: replicated
replicas: 4
placement:
constraints:
"node.role!=manager"
preferences:
spread: node.labels.datacenter
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
volumes:
type: volume
source: myvolume
target: /data
busybox_utility:
image: radial/busyboxplus:curl
command: /bin/sh -c "while true; do echo 'HelloDocker'; curl web_nginx:80; sleep 10; done"
volumes:
myvolume:
docker stack deploy -c example5.yml app5
docker stack services app5
docker service logs app5_busybox_utility
docker stack rm app5