Failed to make TCP connection and Startup check never passed

Expected behavior

The service app is able to connect to service mongo db, and the docker image is pushed to CF and starts successfully

Actual behavior

Unable to connect to the database;
Startup check to succeed: failed to make TCP connection to 10.146.71.243:3000: dial tcp 10.146.71.243:3000: connect: connection refused; process did not exit".

Additional Information

The docker image works well on local windows environment. The File System service (1GB) is binded to the application, since the app and db services are using mounted volumns.

Steps to reproduce the behavior

  1. Login to CF Org and space, push the docker image from private repository
  2. Check the Log

Here are docker files and docker-compose:

Dockerfile
{code}
FROM node:20

WORKDIR /app

COPY package.json ./

COPY yarn.lock ./

RUN yarn

COPY . .

RUN yarn build

EXPOSE 3000

CMD [ “yarn”, “start:prod” ]
{code}

docker-compose.prod.yml
{code}
version: ‘3’

services:
app:
container_name: test-elf-service
build:
context: .
dockerfile: Dockerfile
networks:
- prod_net
volumes:
- prod_volume:/app
ports:
- 3000:3000
environment:
- NODE_ENV=prod
- DB_URI=mongodb://db:27017/test-elf-service
depends_on:
- db

db:
image: mongo
networks:
- prod_net
volumes:
- prod_mongo_volume:/data/db
ports:
- 27017:27017

volumes:
prod_mongo_volume:
prod_volume:

networks:
prod_net:
driver: bridge

{code}

Console logs on CF:
2024-04-24T01:49:38.765+0000 [API/28] STDOUT Creating build for app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:49:39.072+0000 [STG/0] STDOUT Cell abd54a5d-44b4-405d-8423-c5328b9a2a1e creating container for instance 811cc0d2-c9eb-474d-acb9-1e53f434d295
2024-04-24T01:49:39.685+0000 [STG/0] STDOUT Security group rules were updated
2024-04-24T01:49:39.768+0000 [STG/0] STDOUT Cell abd54a5d-44b4-405d-8423-c5328b9a2a1e successfully created container for instance 811cc0d2-c9eb-474d-acb9-1e53f434d295
2024-04-24T01:49:40.134+0000 [STG/0] STDOUT Staging…
2024-04-24T01:49:40.299+0000 [STG/0] STDOUT Staging process started …
2024-04-24T01:49:40.747+0000 [STG/0] STDOUT Staging process finished
2024-04-24T01:49:40.753+0000 [STG/0] STDOUT Exit status 0
2024-04-24T01:49:40.753+0000 [STG/0] STDOUT Staging Complete
2024-04-24T01:49:41.242+0000 [STG/0] STDOUT Cell abd54a5d-44b4-405d-8423-c5328b9a2a1e stopping instance 811cc0d2-c9eb-474d-acb9-1e53f434d295
2024-04-24T01:49:41.242+0000 [STG/0] STDOUT Cell abd54a5d-44b4-405d-8423-c5328b9a2a1e destroying container for instance 811cc0d2-c9eb-474d-acb9-1e53f434d295
2024-04-24T01:49:41.275+0000 [API/9] STDOUT Creating droplet for app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:49:42.656+0000 [API/1] STDOUT Stopping app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:49:42.756+0000 [STG/0] STDOUT Cell abd54a5d-44b4-405d-8423-c5328b9a2a1e successfully destroyed container for instance 811cc0d2-c9eb-474d-acb9-1e53f434d295
2024-04-24T01:49:42.926+0000 [API/6] STDOUT Updated app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206 ({:droplet_guid=>“fcd8c6cb-131a-4c46-b70d-351d434233ff”})
2024-04-24T01:49:43.227+0000 [API/11] STDOUT Creating revision for app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:49:43.268+0000 [API/11] STDOUT Starting app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:49:45.239+0000 [CELL/0] STDOUT Cell 4a288cd8-e47e-45db-b5f0-f59b813a375d creating container for instance b86ff393-cc36-4553-74bc-f798
2024-04-24T01:50:13.735+0000 [CELL/0] STDOUT Security group rules were updated
2024-04-24T01:50:13.815+0000 [CELL/0] STDOUT Cell 4a288cd8-e47e-45db-b5f0-f59b813a375d successfully created container for instance b86ff393-cc36-4553-74bc-f798
2024-04-24T01:50:14.279+0000 [CELL/0] STDOUT Starting health monitoring of container
2024-04-24T01:50:14.544+0000 [APP/PROC/WEB/0] STDOUT yarn run v1.22.19
2024-04-24T01:50:14.572+0000 [APP/PROC/WEB/0] STDOUT $ node dist/main
2024-04-24T01:50:15.330+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[NestFactory] e[39me[32mStarting Nest application…e[39m
2024-04-24T01:50:15.368+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mMongooseModule dependencies initializede[39me[38;5;3m +39mse[39m
2024-04-24T01:50:15.368+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mUtilityModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:50:15.369+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mConfigHostModule dependencies initializede[39me[38;5;3m +1mse[39m
2024-04-24T01:50:15.369+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mAppModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:50:15.369+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 95 - e[39m04/24/2024, 1:50:15 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mConfigModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:50:45.370+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 95 - e[39m04/24/2024, 1:50:45 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (1)…e[39m
2024-04-24T01:51:14.668+0000 [HEALTH/0] STDERR Timed out after 1m0s (30 attempts) waiting for startup check to succeed: failed to make TCP connection to 10.146.71.243:3000: dial tcp 10.146.71.243:3000: connect: connection refused
2024-04-24T01:51:14.668+0000 [CELL/0] STDERR Failed after 1m0.388s: startup health check never passed.
2024-04-24T01:51:14.673+0000 [CELL/SSHD/0] STDOUT Exit status 0
2024-04-24T01:51:18.378+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 95 - e[39m04/24/2024, 1:51:18 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (2)…e[39m
2024-04-24T01:51:51.387+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 95 - e[39m04/24/2024, 1:51:51 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (3)…e[39m
2024-04-24T01:52:20.929+0000 [API/11] STDOUT Process has crashed with type: “web”
2024-04-24T01:52:20.933+0000 [CELL/0] STDOUT Cell 4a288cd8-e47e-45db-b5f0-f59b813a375d stopping instance b86ff393-cc36-4553-74bc-f798
2024-04-24T01:52:20.933+0000 [CELL/0] STDOUT Cell 4a288cd8-e47e-45db-b5f0-f59b813a375d destroying container for instance b86ff393-cc36-4553-74bc-f798
2024-04-24T01:52:20.937+0000 [API/11] STDOUT App instance exited with guid 0fa8c355-25b2-4bfa-ba84-af131d479206 payload: {“instance”=>“b86ff393-cc36-4553-74bc-f798”, “index”=>0, “cell_id”=>“4a288cd8-e47e-45db-b5f0-f59b813a375d”, “reason”=>“CRASHED”, “exit_description”=>“Instance never healthy after 1m0.388s: Timed out after 1m0s (30 attempts) waiting for startup check to succeed: failed to make TCP connection to 10.146.71.243:3000: dial tcp 10.146.71.243:3000: connect: connection refused; process did not exit”, “crash_count”=>1, “crash_timestamp”=>1713923540915869649, “version”=>“b4082fd0-0c32-4df2-8a9c-1bbd8a85bdb8”}
2024-04-24T01:52:21.166+0000 [PROXY/0] STDOUT Exit status 137
2024-04-24T01:52:22.353+0000 [CELL/0] STDOUT Cell 4a288cd8-e47e-45db-b5f0-f59b813a375d successfully destroyed container for instance b86ff393-cc36-4553-74bc-f798
2024-04-24T01:52:22.840+0000 [CELL/0] STDOUT Cell 1ee8c2cb-ca0e-4445-84ec-fb6a1c8ead16 creating container for instance 33871e9d-2ca8-4076-5321-f4b7
2024-04-24T01:52:50.246+0000 [CELL/0] STDOUT Security group rules were updated
2024-04-24T01:52:50.349+0000 [CELL/0] STDOUT Cell 1ee8c2cb-ca0e-4445-84ec-fb6a1c8ead16 successfully created container for instance 33871e9d-2ca8-4076-5321-f4b7
2024-04-24T01:52:50.865+0000 [CELL/0] STDOUT Starting health monitoring of container
2024-04-24T01:52:51.107+0000 [APP/PROC/WEB/0] STDOUT yarn run v1.22.19
2024-04-24T01:52:51.133+0000 [APP/PROC/WEB/0] STDOUT $ node dist/main
2024-04-24T01:52:51.817+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[NestFactory] e[39me[32mStarting Nest application…e[39m
2024-04-24T01:52:51.851+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mMongooseModule dependencies initializede[39me[38;5;3m +34mse[39m
2024-04-24T01:52:51.851+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mUtilityModule dependencies initializede[39me[38;5;3m +1mse[39m
2024-04-24T01:52:51.851+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mConfigHostModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:52:51.851+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mAppModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:52:51.851+0000 [APP/PROC/WEB/0] STDOUT e[32m[Nest] 93 - e[39m04/24/2024, 1:52:51 AM e[32m LOGe[39m e[38;5;3m[InstanceLoader] e[39me[32mConfigModule dependencies initializede[39me[38;5;3m +0mse[39m
2024-04-24T01:53:21.852+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 93 - e[39m04/24/2024, 1:53:21 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (1)…e[39m
2024-04-24T01:53:51.258+0000 [HEALTH/0] STDERR Timed out after 1m0s (30 attempts) waiting for startup check to succeed: failed to make TCP connection to 10.138.47.107:3000: dial tcp 10.138.47.107:3000: connect: connection refused
2024-04-24T01:53:51.258+0000 [CELL/0] STDERR Failed after 1m0.392s: startup health check never passed.
2024-04-24T01:53:51.264+0000 [CELL/SSHD/0] STDOUT Exit status 0
2024-04-24T01:53:54.859+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 93 - e[39m04/24/2024, 1:53:54 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (2)…e[39m
2024-04-24T01:54:15.546+0000 [API/12] STDOUT Stopping app with guid 0fa8c355-25b2-4bfa-ba84-af131d479206
2024-04-24T01:54:15.584+0000 [CELL/0] STDOUT Cell 1ee8c2cb-ca0e-4445-84ec-fb6a1c8ead16 stopping instance 33871e9d-2ca8-4076-5321-f4b7
2024-04-24T01:54:27.864+0000 [APP/PROC/WEB/0] STDERR e[31m[Nest] 93 - e[39m04/24/2024, 1:54:27 AM e[31m ERRORe[39m e[38;5;3m[MongooseModule] e[39me[31mUnable to connect to the database. Retrying (3)…e[39m
2024-04-24T01:54:52.265+0000 [CELL/0] STDOUT Cell 1ee8c2cb-ca0e-4445-84ec-fb6a1c8ead16 destroying container for instance 33871e9d-2ca8-4076-5321-f4b7
2024-04-24T01:54:52.467+0000 [PROXY/0] STDOUT Exit status 137


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```

Here is my Dockerfile:

FROM node:20

WORKDIR /app

COPY package.json ./
COPY yarn.lock ./

RUN yarn

COPY . .

RUN yarn build

EXPOSE 3000

CMD [ "yarn", "start:prod" ]

And my docker-compose.yaml file:

version: '3'

services:
  app:
    container_name: test-elf-service
    build:
      context: .
      dockerfile: Dockerfile
    networks:
      - prod_net
    volumes:
      - prod_volume:/app
    ports:
      - 3000:3000
    environment:
      - NODE_ENV=prod
      - DB_URI=mongodb://db:27017/test-elf-service
    depends_on:
      - db

  db:
    image: mongo
    networks:
      - prod_net
    volumes:
      - prod_mongo_volume:/data/db
    ports:
      - 27017:27017

volumes:
  prod_mongo_volume:
  prod_volume:

networks:
  prod_net:
    driver: bridge