1

docker-compose is not restarting my container even if it is listed with an exit code 2 is docker-compose ps.

      Name                     Command                  State         Ports  
-----------------------------------------------------------------------------
app_autoheal_1      /docker-entrypoint autoheal      Up (healthy)                              
seafile             /sbin/my_init -- /scripts/ ...   Exit 2                  

It is defined in the docker-compose.yaml with restart: always.

version: '3.4'
services:
  autoheal:
    restart: always
    image: willfarrell/autoheal
    environment:
      - AUTOHEAL_CONTAINER_LABEL=all
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  seafile:
    image: seafileltd/seafile-mc:latest
    restart: always
    container_name: seafile
    healthcheck:
      test: ["CMD-SHELL", "test $$(curl -k https://localhost/api2/ping/) = '\"pong\"'"]
      interval: 30s
      timeout: 20s
      retries: 3
      start_period: 30s

In which cases can this happen?

1 Answers1

0

A container exit value of 2 is reserved by Docker. A container should exit 1 to correctly trigger a health check.

The command’s exit status indicates the health status of the container. The possible values are:

  • 0: success - the container is healthy and ready for us
  • 1: unhealthy - the container is not working correctly
  • 2: reserved - do not use this exit code

Source: https://docs.docker.com/engine/reference/builder/#healthcheck

Aaron Adams
  • 333
  • 2
  • 10