docker run -it -d -p 6086:5000 --name dav-backend -v D:\dockerOfficial\dockerPython\django-vue3-admin-master\django-vue3-admin-master:/dav -e TZ=Asia/Shanghai python:3.12.7
# 进入容器
PS ...\django-vue3-admin-master> docker exec -it dav-backend bash
root@e5469745591d:/# ls
bin boot dav dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@e5469745591d:/# cd dav
root@e5469745591d:/dav# ls
CHANGELOG.md LICENSE NOTICE README.md README.zh.md backend docker-compose.yml docker_env init.sh web
// 进入到后端项目源码的目录
root@e5469745591d:/dav# cd backend
root@e5469745591d:/dav/backend# ls
application conf del_migrations.py docker_start.sh dvadmin gunicorn_conf.py logs main.py manage.py plugins requirements.txt static templates
# 根据 requirements.txt 安装依赖
root@e5469745591d:/dav/backend# pip install -r requirements.txt
## 等待依赖安装完成
版本选择:django4.2 支持, 已经搭建好的 PostgreSQL 14.13
...\django-vue3-admin-master> docker exec -it pg01 bash
su - postgres
# 创建数据库
createdb django-vue3-admin
# 切换超级用户
root@705f28c0799b:/# su - postgres
# 创建一个新用户
postgres@705f28c0799b:~$ createuser --interactive --pwprompt
Enter name of role to add: user_dav
Enter password for new role:
Enter it again:
# 询问是否将新角色设置为超级用户
Shall the new role be a superuser? (y/n) n
# 询问是否允许该角色创建新的数据库
Shall the new role be allowed to create databases? (y/n) n
# 询问是否允许该角色创建其他新角色(用户)
Shall the new role be allowed to create more new roles? (y/n) n
# **登录到 PostgreSQL**
psql
# **列出所有数据库**
\l
# 重命名数据库
ALTER DATABASE "django-vue3-admin" RENAME TO django_vue3_admin;
docker run --name redis0 -v D:\dockerOfficial\databases\redis\redis0\data:/data -p 6379:6379 -d docker.1ms.run/redis redis-server --appendonly yes
django-vue3-admin-masterbackendconfenv.example.py
更名为 env.py
import os
from application.settings import BASE_DIR
# ================================================= #
# *************** postgres数据库 配置 *************** #
# ================================================= #
# 使用 `postgres` 时,改为此配置
DATABASE_ENGINE = "django.db.backends.postgresql"
DATABASE_NAME = 'django_vue3_admin'
# 数据库地址 改为自己数据库地址
DATABASE_HOST = 'pg01' # 使用容器名称
DATABASE_PORT = 5432 # PostgreSQL 默认端口
# # 数据库用户名
DATABASE_USER = "user_dav"
# # 数据库密码
DATABASE_PASSWORD = 'DVADMIN3'
# 表前缀
TABLE_PREFIX = "dvadmin_"
# ================================================= #
# ******** redis配置,无redis 可不进行配置 ******** #
# ================================================= #
REDIS_DB = 1
CELERY_BROKER_DB = 3
REDIS_HOST = 'redis0' # 使用容器名称
REDIS_PORT = 6379 # Redis 默认端口
REDIS_URL = f'redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}'
# ================================================= #
# ****************** 功能 启停 ******************* #
# ================================================= #
DEBUG = True
# 启动登录详细概略获取(通过调用api获取ip详细地址。如果是内网,关闭即可)
ENABLE_LOGIN_ANALYSIS_LOG = True
# 登录接口 /api/token/ 是否需要验证码认证,用于测试,正式环境建议取消
LOGIN_NO_CAPTCHA_AUTH = True
# ================================================= #
# ****************** 其他 配置 ******************* #
# ================================================= #
ALLOWED_HOSTS = ["*"]
# 列权限中排除App应用
COLUMN_EXCLUDE_APPS = []
价值:相关容器加入 docker 专用网络, 容器间数据交互,不走宿主机物理网卡堆栈,降低宿主机负载
# 创建 docker_net_198 容器网络
docker network create docker_net_198
# 显示所有容器网络
docker network ls
# 指定容器加入网络
docker network connect docker_net_198 dav-backend
docker network connect docker_net_198 redis0
docker network connect docker_net_198 pg01
# 查看 docker_net_198 网络的详细信息
docker network inspect docker_net_198
python manage.py makemigrations // 生成迁移文件
python manage.py migrate // 应用迁移信息
python run server 0.0.0.0:5000
root@e5469745591d:/dav/backend# python manage.py runserver 0.0.0.0:5000
[2024-11-30 11:41:01][django.utils.autoreload.run_with_reloader():668] [INFO] Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
November 30, 2024 - 11:41:02
Django version 4.2.7, using settings 'application.settings'
Starting ASGI/Channels version 3.0.5 development server at http://0.0.0.0:5000/
Quit the server with CONTROL-C.
/usr/local/lib/python3.12/site-packages/asgiref/sync.py:569: UserWarning: async_to_sync was passed a non-async-marked callable
return AsyncToSync(
[2024-11-30 11:41:02][daphne.server.run():113] [INFO] HTTP/2 support not enabled (install the http2 and tls Twisted extras)
[2024-11-30 11:41:02][daphne.server.run():122] [INFO] Configuring endpoint tcp:port=5000:interface=0.0.0.0
[2024-11-30 11:41:02][daphne.server.listen_success():153] [INFO] Listening on TCP address 0.0.0.0:5000
访问后端 api 文档网址: http://192.168.8.93:6086/