Files
nexus/wiki/concepts/Docker容器化部署.md
2026-04-14 16:02:50 +08:00

58 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Docker容器化部署"
type: concept
tags: [docker, deployment, containerization]
sources: [tiktok-pm-python-django-project.md]
last_updated: 2026-04-14
---
## Definition
Docker容器化部署通过docker-compose编排多个容器实现开发生产环境一致性。
## Architecture
### Services
- **web**Django + Gunicorn应用
- **nginx**:反向代理和静态文件服务
- **MySQL**:外部数据库(也可容器化)
### docker-compose.yml
```yaml
services:
web:
build: .
command: gunicorn tiktok_pm_project.wsgi:application
volumes:
- ./data:/app/data
env_file:
- .env
worker:
build: .
command: python manage.py qcluster
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- web
```
## Deployment Workflow
1. 拉取最新代码git pull origin main
2. 重建容器docker compose up --build -d
3. 执行迁移docker compose exec web python manage.py migrate
4. 创建超级用户docker compose exec web python manage.py createsuperuser
## Static Files
使用collectstatic收集静态文件Nginx提供/static/路由。
## Connections
- [[Docker容器化部署]] ← contains ← [[Django]]
- [[Docker容器化部署]] ← contains ← [[Gunicorn]]
- [[Docker容器化部署]] ← contains ← [[Nginx]]
- [[Docker容器化部署]] ← uses ← [[MySQL]]