Question

Docker compose - (nginx, node.js, react)

Posted September 14, 2021 54 views
NginxNode.jsDocker

Hi,
I have some troubles with my application I am using docker-compose and I have 2 backend node.js apps and 1 react fe. Part of docker-compose is nginx.
After start everything works fine, but in a while (sometimes hours, sometimes minutes) ngnix starts to return error - “*426 upstream timed out (110: Connection timed out) while reading response header from upstream”
The weird part is that on other Droplet everything works fine

upstream fe-wpos {
  server fe-wpos:3000;
}

upstream be-wpos {
  server be-wpos:5000;
}

upstream be-rs-wpos {
  server be-rs-wpos:8081;
}

server {
  listen 80;
  location / {
    proxy_pass http://fe-wpos;
  }
}

server {
  listen 5000;
  location / {
    proxy_pass http://be-wpos;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

server {
  listen 8081;
  location / {
    proxy_pass http://be-rs-wpos;
  }
}

I have no idea what is wrong

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

As the services are working for some time before you get the error, this makes me think that the problem is not related to your docker-compose YAML.

Most likely one of the services is crashing due to an error or due to not enough memory on the server for example.

I would recommend, checking your Docker container logs for some more information.

You could find the logs for a specific container with the following:

  • First get your container ID:
docker ps -a
  • Then once you have the ID check the logs:
docker logs -f container_id

In there you should be able to see any application errors that pop up. If you don’t see any logs, you might have to enable debug mode and try again.

Let me know how it goes!
Best,
Bobby

  • Hi,
    Thank you for your response. I thought the same and the only error I found was “upstream time out”. I fortunately found the situation how to cause the error and the root cause was my error in the code - I forgot to release database connection in one of my API endpoint and in the moment when connection pool was exhausted express stopped responding