Thursday, 28 February 2019

Health Checking With Docker Stack

# Docker Swarm/Stack Compose file 'docker stack deploy <stackname> -c docker-stack-compose.yml
# docker swarm leave --force
# docker swarm init
# docker node update $(docker node inspect self --format '{{.ID}}') --label-add DrupalReady=true
# docker node inspect self --format '{{.Spec.Labels}}'

# docker secret rm postgres_password 
# echo 'SomeSecretPassword!' | docker secret create --label SOMELABEL=WHAT postgres_password -
# docker secret inspect postgres_password

#
#
#
# docker stack deploy drupalstack -c docker-stack-compose.yml 
#  docker stack ps $(docker stack ls --format '{{.Name}}') 
#

# Grab Info on all containers in our current stacks.
# docker container inspect $(docker stack ps --no-trunc $(docker stack ls --format '{{.Name}}') --format '{{.Name}}.{{.ID}}')

version: '3.1'
services:

# DRUPAL MAIN APP 
 drupal:
   image: drupal:8.2
   ports:
    - "8070:80"
   volumes:
     - webdata:/var/www/html

#   healthcheck:
#    test: ["CMD-SHELL", "curl -f http://127.0.0.1 || exit 1"]
#    interval: 20s
#    timeout: 10s
#    retries: 3
#    start-period: 10s
#    disable: true
    
   depends_on:
      - postgres
   deploy:
     replicas: 1
     placement:
        constraints: [node.labels.DrupalReady == true ]

# docker run -p 9009:9009 -v /var/run/docker.sock:/var/run/docker.sock moimhossain/viswar
# STACK VISUALISER
 viz:
  image: bretfisher/visualizer
  ports:
   - "8080:8080"
  volumes:
   - /var/run/docker.sock:/var/run/docker.sock
  deploy:
   placement:
    constraints: [node.role == manager]

# DB 
 postgres:
   image:
    postgres:9.6
   
   healthcheck:
    test: ["CMD-SHELL", "pg_isready -U postgres || exit 1"]
    interval: 30s
    timeout: 10s
    retries: 3
#   start-period: 10s

   secrets:
    - postgres_password

   environment:
    - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
    - POSTGRES_USER=drupaluser
    - POSTGRES_DB=egdbase

   volumes:
       - postgresdata:/var/lib/postgresql/data

   deploy:
    restart_policy:
     condition: on-failure
     delay: 5s
     max_attempts: 3


volumes:
 postgresdata:
 webdata:
secrets:
 postgres_password:
  external: true

No comments:

Post a Comment