python - 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 的情况下在本地下载时,我可以完美地运行它,所以该应用程序可以工作但不能在容器中运行......
请给我一些帮助!
谢谢你
解决方案
我认为您不需要--network,只需尝试docker run --publish 8000:8000 <container_id>
推荐阅读
- kotlin - How to Resolve Function Template Generics for Signal/Slot System?
- javascript - How do I hide NavBar of my website when using in mobile with reactjs?
- crystal-reports - 将多个列值连接成一个字符串 - Crystal Repot 公式
- python - CV2 问题:numpy.core.multiarray 导入失败
- python - Sorting algorithm based on two conditions
- javascript - Multiple version of keyBy in lodash? (Group values sharing a key as an array)
- c# - 使用 C# 进行图像处理以进行货币检测
- c# - 设置实例中的所有布尔属性
- mysql - Go-gorm mysql“不支持的类型[]字符串,一段字符串”
- java - 如何通过其 uid 获取 Firestore 用户列表?