I've tried to up a docker-compose with three services, but it fails on healthcheck.
It is made by searching a specific running port with lsof: test: ["CMD", "lsof", "-t", "-i:3001"]
Nevertheless, when I try to reach the service by that specific port, binded on the docker-compose, it works seamslessly to me.
I've tried to run this command with running container, and this did not work too. So I realized that I should run it with sudo, and, by this way, it returns a sucessfully response (0).
I was looking for use the sudo command and I've found that the Docker Daemon runs on root mode. So it break out my theory.
Someone has some ideia about what can be making my healthcheck don't be sucessfully?
Follow the code:
version: '3.9'
services:
frontend:
container_name: front-end
build: ./src/front-end
ports:
- 3000:3000
restart: on-failure
networks:
- frontend
healthcheck:
test: ["CMD", "lsof", "-t", "-i:3000"]
interval: 10s
timeout: 5s
retries: 5
depends_on:
backend:
condition: service_healthy
backend:
container_name: back-end
build: ./src/back-end
working_dir: /backend
environment:
- BACKEND_PORT=3001
ports:
- 3001:3001
restart: on-failure
networks:
- frontend
- backend
healthcheck:
test: ["CMD", "lsof", "-t", "-i:3001"]
interval: 10s
timeout: 5s
retries: 5
depends_on:
database:
condition: service_healthy
database:
container_name: database
image: mongo:6.0.4
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: ${ECONDOS_MONGODB_USER}
MONGO_INITDB_ROOT_PASSWORD: ${ECONDOS_MONGODB_PASSWORD}
networks:
- backend
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.runCommand({ ping: 1 })", "--quiet"]
interval: 10s
timeout: 5s
retries: 5
networks:
frontend:
backend:
docker-compose -v
docker-compose version 1.29.2, build 5becea4c