strapi-community / strapi-tool-dockerize

Easy add support for docker to your strapi project
MIT License
504 stars 34 forks source link

Error: connect ECONNREFUSED 172.18.0.2:55432 #107

Open AhmedWagdi1 opened 5 months ago

AhmedWagdi1 commented 5 months ago

🐛 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)
Eventyret commented 5 months ago

Default port for poatgres is 5432 not 55432

AhmedWagdi1 commented 5 months ago

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.```
pmeaney commented 3 months ago

Ahmed, Try with the default settings first.

For example:

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