Skip to main content

docker-compose profiles 模式切换

chatgpt-next-web 项目的时候看到的写法, 不看开源项目, 不知道外面多了那么多新配置新功能.

查了docker官方文档, profiles可以支持在不同环境下启动不同的services,一个docker-compose文件即可.

启动的时候可以通过命令行指定, 也可以设置在环境变量里, 并且一次性可以配置多个profiles.

docker compose --profile debug up

docker 官方文档说明

Using profiles with Compose

https://docs.docker.com/compose/profiles/

services:
frontend:
image: frontend
profiles: ["frontend"]

phpmyadmin:
image: phpmyadmin
depends_on:
- db
profiles:
- debug

backend:
image: backend

db:
image: mysql

启动命令, 指定profiles.

 # 命令行直接指定参数
docker compose --profile debug up

# 配置在环境变量里
COMPOSE_PROFILES=debug docker compose up

# 配置多个profiles
docker compose --profile frontend --profile debug up

chatgpt next web docker profiles

https://github.com/Yidadaa/ChatGPT-Next-Web/blob/main/docker-compose.yml


version: '3.9'
services:
chatgpt-next-web:
profiles: ["no-proxy"]
container_name: chatgpt-next-web
image: yidadaa/chatgpt-next-web
ports:
- 3000:3000
environment:
- OPENAI_API_KEY=$OPENAI_API_KEY
- CODE=$CODE
- BASE_URL=$BASE_URL
- OPENAI_ORG_ID=$OPENAI_ORG_ID
- HIDE_USER_API_KEY=$HIDE_USER_API_KEY
- DISABLE_GPT4=$DISABLE_GPT4

chatgpt-next-web-proxy:
profiles: ["proxy"]
container_name: chatgpt-next-web-proxy
image: yidadaa/chatgpt-next-web
ports:
- 3000:3000
environment:
- OPENAI_API_KEY=$OPENAI_API_KEY
- CODE=$CODE
- PROXY_URL=$PROXY_URL
- BASE_URL=$BASE_URL
- OPENAI_ORG_ID=$OPENAI_ORG_ID
- HIDE_USER_API_KEY=$HIDE_USER_API_KEY
- DISABLE_GPT4=$DISABLE_GPT4