version: '3.7'
networks:
nginx:
external: false
services:
nginx:
image: nginx:1.18
ports:
- '8088:80'
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "service", "nginx", "status"]
networks:
- nginx
docker stack deploy -c docker-compose.yml nginx
docker stack ls
docker service ls
docker ps
version: '3.7'
networks:
nginx:
external: false
services:
nginx:
image: nginx:1.19
ports:
- '8088:80'
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "service", "nginx", "status"]
networks:
- nginx
docker stack deploy -c docker-compose.yml nginx
docker stack ls
docker service ls
docker ps
https://medium.com/better-programming/zero-downtime-deployment-with-docker-swarm-d84d8d9d9a14 https://docs.docker.com/compose/compose-file/#update_config
version: '3.7'
networks:
nginx:
external: false
services:
# --- NGINX ---
nginx:
image: nginx:1.19
ports:
- '8088:80'
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: curl --fail -s http://localhost:80/ || exit 1
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
networks:
- nginx
docker ps
docker exec -it containerid bash
Move index.html to /tmp so that health check command will get 400 status code and will become unhealthly
mv /usr/share/nginx/html/index.html /tmp/
check the conatiners again . if health check fails , Docker swarm will kill that container and create the new container
docker service ps
docker ps