【问题标题】:When hitting docker: (56) Recv failure: Connection reset by peer打 docker 时:(56) Recv failure: Connection reset by peer
【发布时间】:2021-05-11 11:01:45
【问题描述】:

我的 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"]

我使用以下方法构建图像:

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

并使用以下命令运行 docker 容器:

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

我的金字塔的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

从容器内部,当我运行时:

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

我得到了我正在寻找的响应。

但是从主机,当我运行时

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

我收到以下错误:

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

我检查了主机的机器防火墙是否已关闭使用:

❯ sudo ufw status verbose
Status: inactive

主机正在运行 Ubuntu:

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

并且宿主机上Docker的版本是:

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

docker ps -a 在宿主机上的输出:

❯ 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

为什么会出现这个错误?如何调试?

【问题讨论】:

  • application.properties 中需要设置0.0.0.0 而不是localhost
  • 是的,我有那套:[server:main] use = egg:gunicorn#main host = 0.0.0.0 port = 8000
  • 不是答案,但您可以尝试与deformdemo 进行比较。

标签: python docker gunicorn pyramid


【解决方案1】:

我终于可以通过在 docker run 命令中添加--bind 8000 来让它工作:

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

【讨论】:

    猜你喜欢
    • 2014-12-20
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 2012-07-15
    • 2019-06-11
    • 2020-06-06
    相关资源
    最近更新 更多