Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: connect ECONNREFUSED 172.18.0.2:55432 #107

Open
AhmedWagdi1 opened this issue Feb 6, 2024 · 3 comments
Open

Error: connect ECONNREFUSED 172.18.0.2:55432 #107

AhmedWagdi1 opened this issue Feb 6, 2024 · 3 comments
Assignees

Comments

@AhmedWagdi1
Copy link

πŸ› 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

> [email protected] 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

> [email protected] 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
Copy link
Member

Default port for poatgres is 5432 not 55432

@AhmedWagdi1
Copy link
Author

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
Copy link

pmeaney commented Mar 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants