2024-05-17 17:00:00 +08:00
|
|
|
|
# 指定API版本号
|
2023-12-15 16:17:51 +08:00
|
|
|
|
version: "3.9"
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 指定文件名称
|
|
|
|
|
name: ${NAME}
|
2023-12-15 16:17:51 +08:00
|
|
|
|
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 服务相关
|
|
|
|
|
services:
|
|
|
|
|
## 服务1
|
2023-12-15 16:17:51 +08:00
|
|
|
|
${SERVICE_NAME}:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 镜像
|
2023-12-15 16:17:51 +08:00
|
|
|
|
image: ${IMAGE_NAME}:${IMAGE_TAG}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器名称
|
2023-12-15 16:17:51 +08:00
|
|
|
|
container_name: ${CONTAINER_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 重启规则
|
2023-12-15 16:17:51 +08:00
|
|
|
|
restart: on-failure:3
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 是否以特权模式启动容器
|
2023-12-15 16:17:51 +08:00
|
|
|
|
privileged: true
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器内用户
|
2023-12-15 16:17:51 +08:00
|
|
|
|
user: ${USER_NAME}:${USER_GROUP}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器内工作目录
|
2023-12-15 16:17:51 +08:00
|
|
|
|
working_dir: ${WORKING_DIR}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 挂载的存储卷或目录
|
2023-12-15 16:17:51 +08:00
|
|
|
|
volumes:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
#### 确保容器内时间和主机一致
|
2023-12-15 16:17:51 +08:00
|
|
|
|
- /etc/localtime:/etc/localtime:ro
|
2024-05-17 17:00:00 +08:00
|
|
|
|
#### 挂载存储卷(需在volumes部分设置卷相关参数)
|
2023-12-15 16:17:51 +08:00
|
|
|
|
- ${VOLUME_NAME}:${CONTAINER_PATH}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
#### 挂载主机目录
|
2023-12-15 16:17:51 +08:00
|
|
|
|
- ${HOST_PATH}:${CONTAINER_PATH}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 使用的配置(需在configs部分设置配置相关参数)
|
2023-12-15 16:17:51 +08:00
|
|
|
|
configs:
|
|
|
|
|
- ${CONFIG_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 使用的凭据(需在secrets部分设置凭据相关参数)
|
2023-12-15 16:17:51 +08:00
|
|
|
|
secrets:
|
|
|
|
|
- ${SECRET_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器内环境变量
|
2023-12-15 16:17:51 +08:00
|
|
|
|
environment:
|
|
|
|
|
- ${KEY}=${VALUE}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 运行容器时执行的命令
|
2023-12-15 16:17:51 +08:00
|
|
|
|
command: ${COMMAND}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 当前服务依赖的容器
|
2023-12-15 16:17:51 +08:00
|
|
|
|
depends_on:
|
|
|
|
|
- ${SERVICE_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器的网络模式
|
2023-12-15 16:17:51 +08:00
|
|
|
|
network_mode: host
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器的端口号
|
2023-12-15 16:17:51 +08:00
|
|
|
|
ports:
|
|
|
|
|
- ${HOST_PORT}:${CONTAINER_PORT}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 容器的网络
|
2023-12-15 16:17:51 +08:00
|
|
|
|
networks:
|
|
|
|
|
- ${NETWORK_NAME}
|
|
|
|
|
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 存储卷相关
|
2023-12-15 16:17:51 +08:00
|
|
|
|
volumes:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 存储卷1
|
2023-12-15 16:17:51 +08:00
|
|
|
|
${VOLUME_NAME}:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 存储卷名称
|
2023-12-15 16:17:51 +08:00
|
|
|
|
name: ${VOLUME_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 是否使用已存在的存储卷
|
|
|
|
|
external: true
|
2023-12-15 16:17:51 +08:00
|
|
|
|
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 配置相关
|
|
|
|
|
configs:
|
|
|
|
|
## 配置1
|
2023-12-15 16:17:51 +08:00
|
|
|
|
${CONFIG_NAME}:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 配置名称
|
2023-12-15 16:17:51 +08:00
|
|
|
|
name: ${CONFIG_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 是否使用已存在的配置
|
|
|
|
|
external: true
|
|
|
|
|
### 配置对应的文件
|
2023-12-15 16:17:51 +08:00
|
|
|
|
file: ${CONFIG_FILE_NAME}
|
|
|
|
|
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 凭据相关
|
2023-12-15 16:17:51 +08:00
|
|
|
|
secrets:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 凭据1
|
2023-12-15 16:17:51 +08:00
|
|
|
|
${SECRET_NAME}:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 凭据名称
|
2023-12-15 16:17:51 +08:00
|
|
|
|
name: ${SECRET_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
### 是否使用已存在的凭据
|
|
|
|
|
external: true
|
|
|
|
|
### 凭据对应的文件
|
|
|
|
|
file: ${SECRddET_FILE_NAME}
|
2023-12-15 16:17:51 +08:00
|
|
|
|
|
2024-05-17 17:00:00 +08:00
|
|
|
|
# 网络相关
|
2023-12-15 16:17:51 +08:00
|
|
|
|
networks:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 网络1
|
2023-12-15 16:17:51 +08:00
|
|
|
|
${NETWORK_NAME}:
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 网络名称
|
2023-12-15 16:17:51 +08:00
|
|
|
|
name: ${NETWORK_NAME}
|
2024-05-17 17:00:00 +08:00
|
|
|
|
## 是否使用已存在的网络
|
|
|
|
|
external: true
|
|
|
|
|
## 网络适配器
|
|
|
|
|
driver: bridge
|
|
|
|
|
## 网络适配器参数
|
|
|
|
|
driver_opts:
|
|
|
|
|
### 是否加密
|
|
|
|
|
encrypted: 'true'
|
|
|
|
|
## 网络参数
|
|
|
|
|
ipam:
|
|
|
|
|
### 适配器
|
|
|
|
|
driver: default
|
|
|
|
|
### 配置
|
|
|
|
|
config:
|
|
|
|
|
#### 网段
|
|
|
|
|
- subnet: 172.21.0.1/24
|