首页 > 解决方案 > Django Docker 问题

问题描述

在为 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 的情况下在本地下载时,我可以完美地运行它,所以该应用程序可以工作但不能在容器中运行......

请给我一些帮助!

谢谢你

标签: pythondjangodockernetworkingdocker-networking

解决方案


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


推荐阅读