我最近开始了一个项目,它使用docker-compose并由多个服务组成,因此在本地安装和调试是一个问题。我开始寻找一种使用docker-compose进行调试的方法,偶然发现了这段documentation
虽然这解释了如何使用Django配置解释器,但我在项目中使用Sanic,因此无法按照教程操作。您能否建议使用docker-compose进行运行/调试配置的模板?
我也阅读了这个post,但它链接到前面提到的文档。
发布于 2020-04-13 16:45:26
我相信,只要稍微修改一下Dockerfile,大部分文档都可以轻松地与Sanic一起使用:
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)发布于 2020-08-07 16:48:47
我建议使用Docker Compose添加一个远程Python环境。对调试非常有用。来自Preferences -> Project Interpreter -> Add... -> Docker Compose。您应该选择您的Docker撰写文件。然后,您可以通过选择远程Python解释器(可以从Run/Debug Configurations中选择它)来简单地运行/调试您的main.py。
PS:在从Pycharm运行应用程序之前,我构建了docker-compose文件。当我直接从Pycharm运行compose文件时,我遇到了一些错误。
https://stackoverflow.com/questions/61120874
复制相似问题