I'm doing docker-compose with my nestjs app but the healthcheck did not work at all, is there something wrong with my config?
version: '3.1'
services:
backend:
image: my_image
ports:
- 3009:3009
environment:
PORT: 3009
DB_NAME: my_db_name
DB_PORT: 5432
DB_USERNAME: postgres
DB_PASSWORD: 992002
DB_HOST: postgres
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:3009" ]
interval: 10s
timeout: 5s
retries: 2
frontend:
image: my_image2
ports:
- 3000:3000
environment:
PORT: 3000
NEXT_PUBLIC_SERVER_URL: http://backend:3009
NEXT_PUBLIC_SERVER_URL_CLIENT_COMPONENT: http://localhost:3009
depends_on:
backend:
condition: service_healthy
I have already had the route to health check here using terminus:
@Controller()
export class AppController {
constructor(
private health: HealthCheckService,
private http: HttpHealthIndicator,
) {}
@Get()
@HealthCheck()
check() {
return this.health.check([
() => this.http.pingCheck('backend', 'http://localhost:3009'),
]);
}
}
And when I docker-compose, my backend always got unhealthy.
I want to make health check the nestjs app and got the healthy_services result but I got unhealthy_services result.



/healthroute, so I would trytest: [ "CMD", "curl", "-f", "http://localhost:3009/health" ]