Z123456789
Z123456789

Reputation: 11

upstream timeout while reading response header from upstream client 172.17.0.1

upstream timeout while reading response header from upstream client 172.17.0.1... 

Getting this error while running a docker image not sure why this error is coming. I tried running the same image on a different computer and it is working fine.

The docker command I used to run this program:

docker run -e "PORT=8765" -p 8007:8765 akash9179/flask-vue  

The full error:

10#10: *2 upstream timed out (110: operation timed out) while reading response header from upstream, client:172.17.0.1, server: request: "GET /users HTTP/1.1", upstream: "http://127.0.0.1:5000/users", host: "localhost:8007", referrer: "http://localhost:8007/".

The Dockerfile ends with:

CMD gunicorn -b 0.0.0.0:5000 app:app --daemon && \
      sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/conf.d/default.conf && \
      nginx -g 'daemon off;'

Upvotes: 0

Views: 1447

Answers (1)

v25
v25

Reputation: 7631

This is most likely due to the way you're invoking the servers in the Dockerfile:

CMD gunicorn -b 0.0.0.0:5000 app:app --daemon && \
      sed -i -e 's/$PORT/'"$PORT"'/g' /etc/nginx/conf.d/default.conf && \
      nginx -g 'daemon off;'

I suspect with this CMD line, nginx doesn't actually run until the gunicorn process sucessfully completes, which as it's running a server it won't.

The correct way to architect this is to have a separate Dockerfile for both the gunicorn server and the nginx server. You're trying to pack too much into a single Dockerfile. Each container should run one process!

You should then define these as separate services in the docker-compose.yml file:

services:
  flask:
    build:
      context: .
      dockerfile: Dockerfile-flask
  nginx:
    build:
      context: .
      dockerfile: Dockerfile-nginx

Within each container the service name (that's flask and nginx) can be used to access the other container in place of a hostname. So in the nginx config, where you do the proxy_pass lines, you could have something like:

  location /ping {
    proxy_pass      http://flask:5000;
  }

Also there's probably no point in that sed line which overwrites the default.conf to change the nginx port number. I would stick with a static nginx port in the config, and then when you do the run command, just have it documented a user knows they need to map their own preferred external port, to that of your nginx server.

This also would avoid the need to pass in PORT as an environment variable.

Upvotes: 1

Related Questions