1

I'm running my containers via a docker compose file. They are in the same network and I can ping from my backend container to my database container. I use the database name as the hostname in the connection string and it doesn't bring any errors that it couldn't find the host. Instead, it just hangs up and times out.

I have a test endpoint which is just suppose to test the connection. When you use that endpoint, database container logs "invalid packet length", and on the frontend, nothing happens, then it times out. I have no idea whats wrong. Any help?

version: '3.2' 
 services: 
  server: 
   restart: always 
   build: 
    dockerfile: Dockerfile 
    context: ./nginx 
   depends_on: 
    - backend 
    - frontend 
    - database 
   ports: 
    - '5000:80' 
   networks: 
    - app_network  
 database: 
  image: postgres:latest 
  container_name: database 
  ports: 
   - "5432:5432" 
  restart: always 
  hostname: database 
  environment: 
   POSTGRES_PASSWORD: 1234 
   POSTGRES_USER: postgres 
    
backend: 
build: 
 context: ./backend 
 dockerfile: ./Dockerfile 
 image: kalendae:backend 
 hostname: backend 
 container_name: backend 
 environment: 
  - WAIT_HOSTS=database:5432 
  - DATABASE_HOST=database 
  - DATABASE_PORT=5432 
  - PORT=5051
frontend: 
build: 
 context: ./frontend 
 dockerfile: ./Dockerfile 
image: kalendae:frontend 
hostname: frontend 
container_name: frontend 
environment: 
 - WAIT_HOSTS=backend:5051 
 - REACT_APP_BACKEND_HOST=localhost 
 - REACT_APP_BACKEND_PORT=5051 
Kustemit
  • 105
  • 1
  • 10
  • Is it possible that the data you're trying to get is too bigger in size? Also, how can I reproduce this issue? Can you please tell me that? – Kartik Chauhan Aug 01 '20 at 09:10
  • Size shouldn't be the problem. It works if the backend is not dockerized, but the database is. To reproduce, create basic nodevexpress server with one endpoint. In the endpoint, use pg client to connect to the database. I use docker compose to run both database and backend. That way, I can use the database service name as hostname. However, it doesn't work. The connection just hangs up when using the endpoint. – Kustemit Aug 01 '20 at 10:56

0 Answers0