Skip to content

Restarting app causes 502 until full stop and restart of entire docker-compose stack #1289

@Redsandro

Description

@Redsandro

Problem:

When a request from shodan.io crashes the smtp-server (see nodemailer/smtp-server#128) in my api app served over https, it is automatically restarted due to docker-compose.yml restart: always.

However, the app doesn't work after restarting: nginx-proxy returns 502.

Expected

  1. The automatic restart should have fixed this.
  2. When I do docker-compose restart api and the logs shows it's listening, I'm still getting 502.
  3. With docker-compose restart restarting everything including nginx-proxy and letsencrypt-nginx-proxy-companion, the logs show listening, but I'm still getting 502.

What works:

A full docker-compose stop && docker-compose up -d brings up the app and everything works. I don't understand the effective difference between docker-compose restart and docker-compose stop && docker-compose up -d, which puzzles me.

But I need to automate this error recovery. I thought restart:always should be sufficient. Is anyone else experiencing something similar? I searched, but I am human. Are there any known issues related to this?

docker-compose.yml

version: "3.5"

networks:
    proxy:
        external:
            name: proxy

volumes:
    conf.d:
    vhost.d:
    html:
    certs:
    db:
        external:
            name: test-db

services:
    nginx:
        image: nginx
        container_name: nginx
        restart: always
        networks:
            - proxy
        ports:
            - 80:80
            - 443:443
        volumes:
            - conf.d:/etc/nginx/conf.d
            - vhost.d:/etc/nginx/vhost.d
            - html:/usr/share/nginx/html
            - certs:/etc/nginx/certs
    nginx-gen:
        image: jwilder/docker-gen
        container_name: nginx-gen
        command: -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
        restart: always
        networks:
            - proxy
        volumes:
            - conf.d:/etc/nginx/conf.d
            - vhost.d:/etc/nginx/vhost.d
            - html:/usr/share/nginx/html
            - certs:/etc/nginx/certs
            - ./nginx.tmpl.go:/etc/docker-gen/templates/nginx.tmpl:ro
            - /var/run/docker.sock:/tmp/docker.sock:ro

    nginx-letsencrypt:
        image: jrtest/letsencrypt-nginx-proxy-companion
        container_name: nginx-letsencrypt
        restart: unless-stopped
        volumes:
            - conf.d:/etc/nginx/conf.d
            - vhost.d:/etc/nginx/vhost.d
            - html:/usr/share/nginx/html
            - certs:/etc/nginx/certs
            # Docker socket for detecting app reboot
            - /var/run/docker.sock:/var/run/docker.sock:ro
        environment:
            NGINX_DOCKER_GEN_CONTAINER: nginx-gen
            NGINX_PROXY_CONTAINER: nginx

    app:
        image: redsandro/test-app:0.4.0
        container_name: test-app
        restart: always
        depends_on:
            - nginx
            - nginx-gen
            - nginx-letsencrypt
        networks:
            - proxy
        environment:
            VIRTUAL_HOST: test-app.example.com
            VIRTUAL_PORT: 8080
            LETSENCRYPT_HOST: test-app.example.com
            LETSENCRYPT_EMAIL: (...)

    api:
        image: redsandro/test-api:0.4.1
        container_name: test-api
        restart: always
        depends_on:
            - db
        networks:
            - proxy
        ports:
            - '25:25'
            - '465:465'
            - '587:587'
        volumes:
            - certs:/certs
        env_file:
            - api.env
        environment:
            TLS_KEY: /certs/test.example.com.key
            TLS_CERT: /certs/test.example.com.crt
            TLS_DHPARAM: /certs/test.example.com.dhparam.pem
            VIRTUAL_HOST: test.example.com
            VIRTUAL_PORT: 9080
            LETSENCRYPT_HOST: test.example.com
            LETSENCRYPT_EMAIL: (...)

    db:
        image: mongo:4.0
        container_name: test-db
        command: 'mongod --smallfiles'
        networks:
            proxy:
                aliases:
                    - mongodb
        volumes:
            - db:/data/db
            - ./initdb.d:/docker-entrypoint-initdb.d
        environment:
            MONGO_INITDB_ROOT_USERNAME: jack
            MONGO_INITDB_ROOT_PASSWORD: ********
            MONGO_INITDB_DATABASE: test-db
        restart: always

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions