跪拜 Guibai
← All articles
Python · Agent · Docker

Local to Live: The Complete Deployment Chain for an AI Project

By 编程干货铺 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Deployment is where many AI projects stall, and this guide names the exact steps and pitfalls, such as certificate-before-domain and exposed database ports. A developer who follows it gets a production-like setup with TLS, container isolation, and persistent data without having to reconstruct the process from scattered resources.

Summary

Deployment for a locally running AI service is a fixed sequence with traps hidden in the ordering. A cloud server comes first, then a domain with DNS pointing at its IP. The HTTPS certificate can only be issued after the domain exists, because the certificate binds to the domain name. In mainland China, that domain also needs ICP filing before it can serve public traffic.

Once infrastructure is up, the project services get containerized. The example AI stack runs FastAPI, MySQL, Redis, MinIO, and Qdrant. Docker Compose writes them all into one file and starts everything with a single command. Containers live on a private network; only Nginx exposes ports, so databases and caches never face the public internet. Named volumes keep data on the host disk, so container deletions don't erase user records or vector indexes.

The deployment itself follows a checklist: ignore build caches, build the frontend to dist, write a .env, upload code, run `docker compose up -d --build`, then run Alembic migrations inside the backend container. Nginx terminates TLS, serves static files, and proxies API calls to the backend, all through one gateway.

Takeaways
— A cloud server is a 24/7 Linux machine; security groups should only expose ports 80, 443, and 22.
— DNS resolution maps a domain to the server's public IP; ICP filing is mandatory for servers in mainland China.
— An HTTPS certificate is bound to a domain, so the domain must be purchased before applying for the certificate.
— Docker Compose lets the whole stack (FastAPI, MySQL, Redis, MinIO, Qdrant) start with one command: docker compose up -d.
— Only Nginx exposes ports to the public; other services communicate over Docker's private internal network, hiding databases and caches from direct access.
— Named volumes like mysql_data and redis_data store data on the host disk, surviving container deletion and recreation.
— The deployment flow includes building the frontend to dist, writing a .env file, uploading code via Git/scp/rsync, and running docker compose up -d --build.
— Alembic migrations create MySQL tables inside the running container: docker compose exec backend alembic upgrade head.
Conclusions

The certificate-after-domain rule is a classic dead end; starting certificate application before owning the domain wastes time and blocks every subsequent step.

Docker's internal network turns containerization into a security boundary, not just a reproducibility tool; the database never gains a public address.

An AI project with a vector store and object storage requires multiple services, making manual server setup error-prone; orchestration is effectively mandatory.

Concepts & terms
Named Volume
A Docker-managed persistent storage area stored on the host disk, outside the container's writable layer. It survives container deletion and recreation, which is why databases and other stateful services mount one.
Reverse Proxy
A server component that sits in front of backend services, accepts client requests, and forwards them to the correct internal service. Here Nginx terminates HTTPS, serves static assets, and routes /api/ calls to the FastAPI container.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗