【问题标题】:Python application giving error deployed through Docker通过 Docker 部署的 Python 应用程序给出错误
【发布时间】:2021-09-17 14:27:55
【问题描述】:

我有我正在部署的 python 应用程序。容器正在正确创建并且已启动并正在运行。但是服务器正在停止并抛出错误。

Dockerfile

FROM python:3.8

# set the working directory in the container
WORKDIR /usr/src/app

# copy the dependencies file to the working directory
COPY requirements.txt ./

# install dependencies
RUN pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY . .

EXPOSE 8000

# command to run on container start

CMD ["python3", "apps/main.py", "start", "--config", "config.yml"]

我在日志中遇到的错误

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sanic/server.py", line 556, in serve
    http_server = loop.run_until_complete(server_coroutine)
  File "uvloop/loop.pyx", line 1501, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1775, in create_server
OSError: [Errno 99] error while attempting to bind on address ('::1', 8000, 0, 0): cannot assign requested address
[2021-09-17 12:50:51 +0000] [97] [INFO] Server Stopped

如果我定义的 dockerfile 或 CMD 命令有任何问题,谁能解释一下。

第一次尝试将主机更新到 0.0.0.0 但不起作用。

错误:

[2021-09-17 15:02:24 +0000] [98] [INFO] Goin' Fast @ http://localhost:8000
[2021-09-17 15:02:24 +0000] [98] [DEBUG] Sanic auto-reload: enabled
[2021-09-17 15:02:24 +0000] [98] [DEBUG] Sanic debug mode: enabled
[2021-09-17 15:02:24 +0000] [98] [ERROR] Unable to start server
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sanic/server.py", line 556, in serve
    http_server = loop.run_until_complete(server_coroutine)
  File "uvloop/loop.pyx", line 1501, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1775, in create_server
OSError: [Errno 99] error while attempting to bind on address ('::1', 8000, 0, 0): cannot assign requested address
[2021-09-17 15:02:24 +0000] [98] [INFO] Server Stopped

【问题讨论】:

  • 可以加docker ps -a输出吗?
  • f79c123f5547 smt:latest "python3 smartinsigh..." 5 秒前 Up 4 seconds 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp
  • 并且您收到了添加到容器日志中的问题的错误?如果它们是主机操作系统日志,请注意
  • 是的,仅在容器日志中我收到此错误
  • 你按照什么教程来创建沉没的应用程序?您是否尝试过使用相同的命令在本地运行此服务器?

标签: python docker sanic


【解决方案1】:

绑定到“0.0.0.0”(所有 NIC)似乎在将其硬编码到 app.start 函数后解决了该问题。 之前用来绑定ipv6 localhost地址(::1)

【讨论】:

    猜你喜欢
    • 2018-07-26
    • 2011-07-12
    • 2021-04-01
    • 1970-01-01
    • 2017-06-12
    • 2021-02-11
    • 2017-04-23
    • 2020-11-08
    • 2019-07-08
    相关资源
    最近更新 更多