curl Recv failure: Connection reset by peer – when hitting nginx docker container

I’m trying to run nginx + gunicorn + flask on a raspberry pi via docker containers.

Gunicorn/flask are packaged together in one container and it works fine.

After I run docker-compose up it’s container is exposed on port 8080 where as the nginx container is exposed on port 5000.

CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                                     NAMES
49ab114042e6        tobi312/rpi-nginx:alpine                   "/usr/bin/ n…"   2 hours ago         Up 2 hours          80/tcp, 443/tcp,>5000/tcp   dev_nginx_1
9c48011b5b08        XXX/YYY:latest                             "/bin/sh -c 'gunicor…"   2 hours ago         Up 2 hours>8080/tcp                    web

I can hit endpoints hosted on the web container just fine.

However, when I try hitting the endpoint via port 5000 which is the port exposed by the nginx container I get the following error:

curl Recv failure: Connection reset by peer

This leads me to believe that my nginx or docker-compose configurations may be wrong.

Below are the relevant files:


version: '3.7'

    image: XXX/YYY:latest
    container_name: web
      - 8080:8080

    image: tobi312/rpi-nginx:alpine
      - 5000:5000
      - /nginx/conf/:/etc/nginx/sites-enabled/:ro
      - web


upstream lazy_upstream {
    server web:8080;

server {

    listen 5000;

    location / {
        proxy_pass http://lazy_upstream;

Does anything pop out to anybody?

Would really appreciate any help!

Source: StackOverflow