首页 > 解决方案 > pycharm docker-compose 调试

问题描述

我最近开始研究一个使用 docker-compose 并由多个服务组成的项目,因此在本地安装和调试一直是个问题。我开始寻找一种使用 docker-compose 进行调试的方法,并遇到了这篇文档

虽然这解释了如何使用 Django 配置解释器,但我在项目中使用 Sanic,因此无法按照 T 的教程进行操作。您能否就使用 docker-compose 的运行/调试配置模板提供建议?

我也阅读了这篇文章,但它链接到上述文档。

标签: debuggingdocker-composepycharmsanic

解决方案


我相信大多数文档应该很容易与 Sanic 一起使用,只要您Dockerfile稍微修改一下:

FROM python:3.7

WORKDIR /app

# By copying over requirements first, we make sure that Docker will cache
# our installed requirements rather than reinstall them on every build
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Now copy in our code, and run it
COPY . /app
EXPOSE 8000
CMD ["python", "main.py"]

然后在main.py

from sanic import Sanic

app = Sanic("MyApp")

# ...

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

推荐阅读