1

我正在尝试测试我的 Quart 应用程序(寻呼机),该应用程序连接到名为 master-db 的 docker 容器中的 MySQL 实例,但经过几次重试后,我收到了 hypercorn 错误:

pager    | Traceback (most recent call last):
pager    |   File "/usr/local/bin/hypercorn", line 8, in <module>
pager    |     sys.exit(main())
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/__main__.py", line 267, in main
pager    |     run(config)
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/run.py", line 34, in run
pager    |     worker_func(config)
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/asyncio/run.py", line 187, in asyncio_worker
pager    |     _run(
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/asyncio/run.py", line 229, in _run
pager    |     loop.run_until_complete(main(shutdown_trigger=shutdown_trigger))
pager    |   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
pager    |     return future.result()
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/asyncio/run.py", line 69, in worker_serve
pager    |     sockets = config.create_sockets()
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/config.py", line 177, in create_sockets
pager    |     insecure_sockets = self._create_sockets(self.bind)
pager    |   File "/usr/local/lib/python3.9/site-packages/hypercorn/config.py", line 240, in _create_sockets
pager    |     sock.bind(binding)
pager    | socket.gaierror: [Errno -2] Name does not resolve
pager exited with code 1

该代码在本地工作并且已经过全面测试,但我不知道我哪里出错了:(

docker-compose 文件是:

  version: "3.8"

  networks:
    localdev:
      driver: bridge

  services:
    master-db:
      image: mysql:8.0
      container_name: master-db
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      ports:
        - "4000:3306"
      environment:
        MYSQL_ROOT_PASSWORD: password_for_stackoverflow
      volumes:
        - ./database/docker:/etc/mysql/conf.d
      networks:
        - localdev

    pager:
      build:
        context: .
        dockerfile: Dockerfile.pager
      container_name: pager
      ports:
        - "2020:2020"
      networks:
        - localdev
      depends_on:
        - master-db

Docker.pager:

FROM python:3-alpine
RUN pip install --upgrade pip
RUN pip install hypercorn
RUN pip install mysql-connector
RUN pip install quart
COPY src/common /app/common
COPY src/pager /app/pager
WORKDIR /app
CMD ["hypercorn", "pager:app", "--bind", "'0.0.0.0:2020'"]
4

1 回答 1

0

问题不在于您无法连接到 MySQL 实例,问题在于 Hypercorn 正在尝试侦听套接字并失败。

CMD ["hypercorn", "pager:app", "--bind", "'0.0.0.0:2020'"]

您是否尝试过从 bind 参数中删除单引号?

CMD ["hypercorn", "pager:app", "--bind", "0.0.0.0:2020"]

于 2022-01-21T14:47:56.980 回答