简体   繁体   English

击中 docker 时:(56)接收失败:对等方重置连接

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

My Dockerfile:我的 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 容器:

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

My pyramid's development.ini file:我的金字塔的development.ini文件:

###
# 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:主机运行 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版本为:

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

The output of docker ps -a on the host machine: docker ps -a在主机上的 output :

❯ 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:通过将--bind 8000添加到 docker 运行命令,我终于能够让它工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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