From native map code to production-grade LangGraph Platform deployment - in-depth explanation of 4 necessary files, LangGraph CLI build process, Docker containerization and docker-compose multi-service orchestration.
LangGraph Platform is provided by LangChain for applying LangGraphDeployed as a production-grade serviceplatform. It provides REST API interface, persistent storage, streaming output support, and conversation thread management capabilities.
This section is built with Module 5task_mAIstroTake the application as an example to show how to package and deploy a local map code as a service that can be accessed externally.
When running the graph locally, the state is stored in memory (InMemoryStore), the data disappears when the process is restarted and cannot be accessed by other clients. LangGraph Platform packages graphs as HTTP services, uses PostgreSQL for persistent storage, and Redis for message queues. It supportsMulti-user, multi-thread, disconnection and reconnectionproduction scene.
To create a LangGraph Platform deployment, you need tomodule-6/deployment/Prepare the following 4 files in the directory:
LangGraph API configuration file declares the graph to be deployed, path mapping and operating environment.
The core logic file of the application, including the nodes, edges, and compiled code of the graph (migrated from Module 5).
A list of Python dependencies that LangGraph CLI automatically installs when building a Docker image.
Runtime environment variables (API keys, database URIs, etc.), passed into the container via file or compose.
// langgraph.json — 声明图的路径和 Python 版本
{
"graphs": {
"task_maistro": "./task_maistro.py:graph"
},
"python_version": "3.11",
"dependencies": ["."]
}
The format is"图名称": "文件路径:图变量名". After deployment, the graph name becomes part of the API endpoint path.
langgraph
langchain-deepseek
trustcall
langchain-core
python-dotenv
module-6/deployment/The directory already contains complete examples of these 4 files for direct reference. Among themdocker-compose-example.ymlYou need to copy and fill in the actual environment variables before use.
LangGraph CLI is a command line tool provided by LangChain for packaging graph code into a Docker image (i.e. LangGraph Server container).
pip install -U langgraph-cli
# 进入部署目录
cd module-6/deployment
# 构建 Docker 镜像,-t 指定镜像名称
langgraph build -t my-image
langgraph buildwill read the files in the current directorylanggraph.json, automatically:
requirements.txtall dependencies inrunlanggraph buildBefore doing this, make sure it is installed and started locally.Docker Desktop. The build process requires network access to pull the base image.
LangGraph Server relies on two external services for infrastructure:
| service | use | Configuration parameters |
|---|---|---|
| PostgreSQL | Persistent storage graph state (checkpointer) and Store data, data will not be lost after restarting | DATABASE_URI(such aspostgresql://user:pass@host/db) |
| Redis | Message queue, supporting streaming output and asynchronous task scheduling | REDIS_URI(such asredis://localhost:6379) |
# 如果 Redis 和 PostgreSQL 已在别处运行,直接启动 API 容器
docker run \
--env-file .env \
-p 8123:8000 \
-e REDIS_URI="redis://localhost:6379" \
-e DATABASE_URI="postgresql://user:pass@localhost/langgraph" \
-e LANGSMITH_API_KEY="lsv2_..." \
my-image
After startup, LangGraph Server listens to port 8000 in the container by default.-p 8123:8000Maps to host port 8123.
If you do not have independent Redis/PostgreSQL, you can usedocker-compose.ymlStart all three services with one click:
# docker-compose.yml 中定义的三个服务
services:
langgraph-redis:
image: redis:6 # 使用官方 Redis 镜像
ports: ["6379:6379"]
langgraph-postgres:
image: postgres:16 # 使用官方 PostgreSQL 镜像
environment:
POSTGRES_DB: langgraph
POSTGRES_USER: langgraph
POSTGRES_PASSWORD: langgraph
ports: ["5433:5432"]
langgraph-api:
image: ${IMAGE_NAME} # 使用 langgraph build 构建的镜像
ports: ["8123:8000"]
depends_on:
langgraph-redis: { condition: service_healthy }
langgraph-postgres: { condition: service_healthy }
env_file: .env # 从 .env 文件读取 API 密钥等环境变量
docker-compose-example.ymlfordocker-compose.yml.envFill in the fileIMAGE_NAME、LANGSMITH_API_KEY、DEEPSEEK_API_KEYcd module-6/deployment
docker compose up
langgraph-apiContainer is set updepends_onThe condition isservice_healthy, which means that LangGraph Server will only start after both Redis and PostgreSQL pass the health check, avoiding startup failure caused by dependent services not being ready.
| Dimensions | Self-hosted | LangGraph Cloud |
|---|---|---|
| infrastructure | Self-maintain Redis, PostgreSQL, Docker | LangChain management, no need to care about the underlying layer |
| Data control | Full control, data never leaves your own server | Data is hosted on LangChain cloud |
| Deployment complexity | DevOps capabilities required | One-click deployment (via LangSmith console) |
| cost model | Billed based on own server cost | Billed by API call volume |
| Applicable scenarios | Enterprise scenarios with strict compliance requirements and sensitive data | Rapid prototyping, small and medium-sized applications |
| LangGraph CLI | langgraph build + docker compose up | Click deploy directly on the LangSmith interface |
The URL used in subsequent Lesson 2 (Connecting)https://langchain-academy-*.langgraph.appIt is a task_mAIstro instance that has been deployed on LangGraph Cloud. Students can directly connect and experience the complete production-level API without deploying it themselves.