gpt4 book ai didi

django - 使用pycharm在docker中运行django

转载 作者:行者123 更新时间:2023-12-02 19:35:37 26 4
gpt4 key购买 nike

我正在尝试在我的Django项目中使用PyCharm进行远程调试。我创建了一个Dockerfile:

FROM python:3.6

WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .
RUN python manage.py makemigrations
RUN python manage.py migrate

EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

并成功使用 docker build -t dockering .创建图像。我可以查看它:
$  docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58e102ea8aaf dockering:1.0 "python -u /opt/.p..." 11 minutes ago Created peaceful_babbage
b10984d7f177 9adf577a7852 "python manage.py ..." 12 minutes ago Exited (137) 8 minutes ago

并使用 docker run -p 8000:8000运行它,并成功输入我的本地主机:8000。但是,当我尝试在PyCharm中执行此操作时,它似乎无法找到正确的图像。

我在设置中设置了正确的解释器:

Settings

并设置命令:

Command

但是,当我尝试运行它时,我有:

890e40a906dd:python -u /opt/project/manage.py runserver localhost:8000 Performing system checks...

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. August 01, 2017 - 08:47:56 Django version 1.11, using settings 'dockering.settings' Starting development server at http://localhost:8000/ Quit the server with CONTROL-C.



正如您可以想象的那样,输入localhost:8000告诉我该网站不起作用。我错过了什么?

最佳答案

我有一个类似的问题,因为我的manage.py runserver指向0.0.0.0:8000,而PyCharm中的Django配置则指向localhost。当我将它们全部设置为0.0.0.0:8000时,它起作用了。

关于django - 使用pycharm在docker中运行django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45433141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com