strapi-community/strapi-tool-dockerize

Error: connect ECONNREFUSED 172.18.0.2:55432

AhmedWagdi1 opened this issue ยท 3 comments

๐Ÿ› Bug Report

Im have this error when i try to run docker compose up --build :
Error: connect ECONNREFUSED 172.18.0.2:55432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)

๐Ÿคทโ€โ™€๏ธ What did you do

i have used the tool to generate the dockerfile and docker-compose.yaml file .. then i tried to run the app using docker compose up --build , defined hosts for db as localhost and port as 55432

my docker compose file :

version: '3'
services:
  xtech:
    container_name: xtech
    build: .
    image: xtech:latest
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT: ${DATABASE_CLIENT}
      DATABASE_HOST: xtechDB
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PORT: ${DATABASE_PORT}
      JWT_SECRET: ${JWT_SECRET}
      ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      NODE_ENV: ${NODE_ENV}
    volumes:
      - ./config:/opt/app/config
      - ./src:/opt/app/src
      - ./package.json:/opt/package.json
      - ./package-lock.json:/opt/package-lock.json

      - ./.env:/opt/app/.env
      - ./public/uploads:/opt/app/public/uploads
    ports:
      - '1337:1337'
    networks:
      - xtech
    depends_on:
      - xtechDB
      
  xtechDB:
    container_name: xtechDB
    platform: linux/amd64 #for platform error on Apple M1 chips
    restart: unless-stopped
    env_file: .env
    image: postgres:14.5-alpine
    environment:
      POSTGRES_USER: ${DATABASE_USERNAME}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      POSTGRES_DB: ${DATABASE_NAME}
    volumes:
      - xtech-data:/var/lib/postgresql/data/ #using a volume
      #- ./data:/var/lib/postgresql/data/ # if you want to use a bind folder

    ports:
      - '55432:55432'
    networks:
      - xtech
      
  xtechAdminer:
    container_name: xtechAdminer
    image: adminer
    restart: unless-stopped
    ports:
      - '9090:8080'
    environment:
      - ADMINER_DEFAULT_SERVER=xtechDB
    networks:
      - xtech
    depends_on:
      - xtechDB

volumes:
  xtech-data:

networks:
  xtech:
    name: Xtech
    driver: bridge

โ›”๏ธ Error log

Error: connect ECONNREFUSED 172.18.0.2:55432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)

๐Ÿ•ต๏ธโ€โ™€๏ธ Stack trace

> x-tech@0.1.0 develop
> strapi develop

- Building build context

[INFO] Including the following ENV variables as part of the JS bundle:
    - ADMIN_PATH
    - STRAPI_ADMIN_BACKEND_URL
    - STRAPI_TELEMETRY_DISABLED
โœ” Building build context (69ms)
- Creating admin

> x-tech@0.1.0 develop
> strapi develop

- Building build context

[INFO] Including the following ENV variables as part of the JS bundle:
    - ADMIN_PATH
    - STRAPI_ADMIN_BACKEND_URL
    - STRAPI_TELEMETRY_DISABLED
โœ” Building build context (64ms)
- Creating admin
โœ” Creating admin (18349ms)
- Loading Strapi
[ERROR]  There seems to be an unexpected error, try again with --debug for more information 

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                                           โ”‚
โ”‚   Error: connect ECONNREFUSED 172.18.0.2:55432                            โ”‚
โ”‚       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)   โ”‚
โ”‚                                                                           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
 *  Terminal will be reused by tasks, press any key to close it. 

## ๐Ÿ™‡โ€โ™€๏ธ Expected behavior/code

Show have start the app normally and connect to database 

## ๐Ÿ‘ฉโ€๐Ÿ’ป Environment

- ๐Ÿ“ฆ Node version: 18 (based on the docker compose file)

Default port for poatgres is 5432 not 55432

it worked after changing mapping to default port ,, thank you

but now it is not creating the user as expected . i get

xtechDB       | 2024-02-06 13:55:51.451 UTC [35] FATAL:  password authentication failed for user "xtechdbuser"
xtechDB       | 2024-02-06 13:55:51.451 UTC [35] DETAIL:  Role "xtechdbuser" does not exist.```

Ahmed, Try with the default settings first.

For example:

  • example run 1: Use all default settings. Run with docker-compose up (note: the strapi-tools-dockerize project will generate new keys in the .env file everytime it is setup)
  • example run 2: Set your own env vars, in the .env file, as shown below. Run with docker-compose up
  • example run 3: Maybe for this example, start trying to use the Dockerfile.prod file by specifying it in the docker-compose.yml file, OR, by using docker build on the Dockerfile.prod, then publishing it to a docker container registry, and specifying the published image as the strapi container to use, in the docker-compose.yml file.

You'll need to set these items as env vars, in the .env file. For "someKeyFromRandomKeyGenerator" I recommend using a key generator to generate a random key for those items.

These are all the items you'll need in the .env file. And this assumes you have the project use postgres as the database.

DATABASE_CLIENT=postgres
DATABASE_HOST=localhost
DATABASE_NAME=strapi
DATABASE_USERNAME=strapi
DATABASE_PASSWORD=someGoodPassword
DATABASE_PORT=5432
JWT_SECRET=someKeyFromRandomKeyGenerator
ADMIN_JWT_SECRET=someKeyFromRandomKeyGenerator
NODE_ENV=development

# has to be 0.0.0.0 to be reached by laptop running locally
HOST=0.0.0.0
# HOST=localhost
PORT=1337
APP_KEYS=someKeyFromRandomKeyGenerator1,someKeyFromRandomKeyGenerator2,someKeyFromRandomKeyGenerator3,someKeyFromRandomKeyGenerator4
API_TOKEN_SALT=someKeyFromRandomKeyGenerator
TRANSFER_TOKEN_SALT=someKeyFromRandomKeyGenerator