【问题标题】:Can't reach server endpoints when running Docker Compose Python Interpreter运行 Docker Compose Python Interpreter 时无法到达服务器端点
【发布时间】:2023-01-31 18:54:54
【问题描述】:

我在 docker-compose.yaml 中为一些服务做了一个小设置。为简洁起见,这是用作使用其他服务的主要 API 的服务:

services:

  fprint-api:
    container_name: fprint-api-v2
    image: "fprint-api:v0.0.1"
    depends_on:
      - fprint-svc

    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "8000:8000"

    build:
      context: ../.
      dockerfile: docker/Dockerfile.fprint-api

  # ...

fprint-api 有一个简单的健康检查端点,如下所示:

@app.get("/health")
def health():
    return "API OK"

如果我只是在上面运行docker-compose up,或者在 PyCharm 中使用 Docker Compose 运行配置,一切正常,我可以向 http://localhost:8000 发出 GET 请求。

但是,如果我在 docker-compse.yamlfprint-api 服务上使用远程 python 解释器,我将无法再到达此端点。系统启动,但端点不可访问,因此我无法调试我的端点。

我不确定我到底错过了什么。

远程解释器配置

fprint-api 服务的运行配置

【问题讨论】:

    标签: networking docker-compose pycharm uvicorn


    【解决方案1】:

    好的,这是一个简单的。

    uvicorn 需要将 --host 标志设置为 0.0.0.0,以便能够通过主机名 localhost 访问 URL:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 2021-04-10
      • 2017-06-02
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      相关资源
      最近更新 更多