简体   繁体   中英

When hitting docker: (56) Recv failure: Connection reset by peer

My Dockerfile:

FROM python:3.8

COPY . /code
WORKDIR /code
    
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils build-essential python3-wheel
RUN pip install -e .
RUN pip install -r test-requirements.txt

CMD ["gunicorn", "--paste", "development.ini", "--workers", "2", "--timeout", "9999", "--graceful-timeout", "60", "--limit-request-field_size", "0", "--reload"]

I build the image using:

docker build -t dukaansvc:v1 -f build/Dockerfile .

and run the docker container using:

docker run -it -d -p 8000:8000 --name mypyramidapp dukaansvc:v1

My pyramid's development.ini file:

###
# app configuration
# https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###

[app:main]
use = egg:dukaan

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_debugtoolbar


###
# wsgi server configuration
###

[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 8000


[loggers]
keys = root, dukaan

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_dukaan]
level = DEBUG
handlers =
qualname = dukaan

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s

From inside the container, when I run:

curl http://localhost:8000/v1/users

I get back the response I am looking for.

But from the host machine, when I run

curl http://localhost:8000/v1/users

I get the following error:

curl: (56) Recv failure: Connection reset by peer

I checked that the host's machine firewall is turned off using:

❯ sudo ufw status verbose
Status: inactive

The host machine is running Ubuntu:

❯ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

And the version of Docker on the host machine is:

❯ docker --version
Docker version 20.10.2, build 2291f61

The output of docker ps -a on the host machine:

❯ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                    NAMES
05874646c63b   dukaansvc:v1   "gunicorn --paste de…"   25 seconds ago   Up 22 seconds   0.0.0.0:8000->8000/tcp   mypyramidapp

Why am I getting that error? How do I debug it?

I was finally able to get it to work by adding --bind 8000 to the docker run command:

CMD ["gunicorn", "--paste", "development.ini", "--bind", ":8000", "--workers", "3", "--reload"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM