【问题标题】:Django Docker problemsDjango Docker 问题
【发布时间】:2021-08-10 22:14:31
【问题描述】:

我在为我的 django 应用程序创建 docker 容器时遇到了一些问题。

我有我的 Dockerfile

FROM python:3.8.6
ENV PYTHONUNBUFFERED 1

USER root

RUN apt-get -y update && \
apt -y install python3-pip && \
pip3 install setuptools gitpython && \
pip install django && \
pip install stripe && \
pip install django-extensions

RUN git clone https://github.com/***/***
WORKDIR /tfg/MiTfg
EXPOSE 8000/tcp


CMD python3 manage.py makemigrations
CMD python3 manage.py migrate
CMD python3 manage.py runserver localhost:8000

完美运行,现在我运行

docker run --network host -p 8000:8000 1fbe

输出打印:

WARNING: Published ports are discarded when using host network mode
System check identified some issues:

WARNINGS:
Tienda.Categoria: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.Cliente: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.CodigoDescuento: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.ContadorSesiones: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.Pedido: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.Producto: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
Tienda.Productor: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the TiendaConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

System check identified 7 issues (0 silenced).

我认为问题出在连接上,因为如果我在浏览器 localhost:8000 中运行,它会说没有服务器在该目录中运行...所以可能是 docker 和主机之间的网络有问题...? ?

当 django 应用程序在没有 docker 的情况下在本地下载时,我可以完美运行它,因此该应用程序可以工作但不能在容器中...

请帮帮我!!!

谢谢你

【问题讨论】:

    标签: python django docker networking docker-networking


    【解决方案1】:

    我认为您不需要 --network,只需尝试 docker run --publish 8000:8000

    【讨论】:

      【解决方案2】:

      首先你不能在一个 Dockerfile 中有多个 CMD,请阅读文档here

      关于它没有绑定到本地端口的问题,尝试运行如下命令: docker run -p 8000:8000 <my_image>

      【讨论】:

        猜你喜欢
        • 2020-04-01
        • 2021-01-02
        • 1970-01-01
        • 1970-01-01
        • 2020-01-17
        • 1970-01-01
        • 2017-12-18
        • 2020-07-11
        • 1970-01-01
        相关资源
        最近更新 更多