Skip to content

fix: update HEALTHCHECK target in Dockerfile from localhost to 127.0.0.1 #100

Description

@ModischFabrications

The cutsolver-frontend container gets marked as unhealthy by Docker, even though the application is running normally and serves traffic successfully.

Why this happens:

  1. The Dockerfile currently defines the health check using localhost:
    HEALTHCHECK --interval=1m --timeout=5s CMD wget -q --spider http://localhost:80/ || exit 1

  2. Inside the Alpine/Nginx container, the /etc/hosts file maps localhost to both IPv4 127.0.0.1 and IPv6 ::1.

  3. Alpine's wget resolves localhost to ::1 (IPv6) first and attempts to connect to [::1]:80.

  4. Since the default Nginx configuration inside the container only listens on IPv4 (0.0.0.0:80) and does not listen on IPv6 ([::]:80), the connection is refused, resulting in:
    Connecting to localhost:80 ([::1]:80)
    wget: can't connect to remote host: Connection refused

Solution:

Change the health check target in the Dockerfile to explicitly use the IPv4 loopback address (127.0.0.1), where Nginx is listening.

-HEALTHCHECK --interval=1m --timeout=5s CMD wget -q --spider http://localhost:80/ || exit 1
+HEALTHCHECK --interval=1m --timeout=5s CMD wget -q --spider http://127.0.0.1:80/ || exit 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions