Docker curl: (56) Recv failure

Hello guys,

I am novice with Docker :frowning:
I have this error :
curl -v localhost:8080
curl: (56) Recv failure

My Dockerfile :

FROM python:latest
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
VOLUME /usr/src/app
EXPOSE 8080
CMD [ “python”, “./server.py” ]

docker build -t api .
With my latop 0 problem, with docker curl: (56) Recv failure

Logs my service web Python :
docker run --name api -p 8080:8080 api

  • Serving Flask app “server” (lazy loading)
  • Environment: production
    WARNING: Do not use the development server in a production environment.
    Use a production WSGI server instead.
  • Debug mode: off
    /usr/local/lib/python3.7/site-packages/flask_sqlalchemy/init.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
    'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and ’
  • Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)

After 1 curl, 0 signal :frowning:

Do you have idea ?

THX

Hi creaprog,
I have a very trivial question.
Are you overwriting the default flask port (5000) within server.py somehow?
If not, I think your issue might be related to the fact that you are mapping the wrong port number.
You should instead try -p 8080:5000
I hope it helps.

Yes.

thx but, same problem :frowning:

What happens when you try curling from within the container 5000?
If that works. My next worry would be to look for your machine firewall specs.
56 from curl means the connection was reset.
Do you have a running firewall? You might have to allow 8080.

In my container : curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused

I don’t have firewall, same error with my Mac. I have try with ubuntu and Mac.

Oh! Within the container? Interesting! This means that your flask server is not running (crashed) or that you are using a flask config that has overwritten the default port 5000 (may be 8080?). In case of a crash, may be try to attach to the running container and investigate that. Then try running the flask server yourself to see the reason of the crash. Otherwise investigate the appropriate internal port your server is running off and that may work for the mapping.

I have the same problem he does : https://github.com/moby/moby/issues/21650

My serer flask don’t crash because i see the log.

With container off :
curl: (7) Failed to connect to 127.0.0.1 port 8080

With container on :
curl: (56) Recv failure

YEAH !!! SOLVED

Before :
if name == “main”:
app.run(debug=True, port=8080)

After :
if name == “main”:
app.run(debug=True, port=8080, host=‘0.0.0.0’)

THX :slight_smile:

1 Like

Make sure you run your service as 0.0.0.0:{port} rather than 127.0.0.1:{port}.

Thank You
It’s worked for me :slight_smile:

Hi
It’s not working for me i have allowed any host as you can see

docker run -p 8002:8002 -it python:3.7-slim python3 -m http.server --bind 0.0.0.0 8002
╰─➤  curl http://localhost:8002                                                                                                                                                            56 ↵
curl: (56) Recv failure: Connection reset by peer

Where and how do you run curl?

I do run the curl within the same Ubuntu server where I initiated the docker container

But if i do the curl with this IP curl http://172.17.0.1:8002 then it works

Which OS, special firewall setup, how did you install Docker?

I am only using iptables

Works for me with localhost. On Debian with Docker installed via convenience install script.

Docker by default updates the firewall automatically to open the ports for the ones you want the container to listen to on host.

The port is allowed already otherwise how am I able to access the response on this IP curl http://172.17.0.1:8002 but not on localhost ip

Hi, having the same issue …

if I call the public ip via the browser I can access the docker but if I try with 0.0.0.0 or 127.0.0.1 I am getting the following error
curl: (56) Recv failure: Connection reset by peer

I am using Ubuntu 22.04.2 LTS

thanks