BookSystem/docker-compose/docker-compose.yml

52 lines
1.4 KiB
YAML
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.

version: '3.8'
services:
# 数据库
postgres:
image: postgres:17
container_name: bs-postgres
restart: always
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
ports:
- "${DB_PORT}:5432"
volumes:
- ${DB_DATA_PATH}:${CONTAINER_BASE_PATH}/postgresql/data #此处使用主机的实际路径不用再写顶层的volumes
networks:
- bs-network
# redis
redis:
image: redis:8.4.1-alpine
container_name: bs-redis
restart: always
ports:
- "${REDIS_PORT}:6379"
command: >
redis-server
--requirepass ${REDIS_PASSWORD}
--dir ${CONTAINER_BASE_PATH}/data
--logfile ${CONTAINER_BASE_PATH}/redis/logs/redis-server.log
environment:
- TZ=Asia/Shanghai
volumes:
# 数据持久化:宿主机路径 -> 容器/dataRedis默认数据目录
- type: bind
source: ../redis/data
target: ${CONTAINER_BASE_PATH}/data/
bind:
create_host_path: true # 自动创建宿主机目录(无需手动建)
# 日志挂载:宿主机路径 -> 容器日志目录
- type: bind
source: ../redis/logs
target: ${CONTAINER_BASE_PATH}/redis/logs/
bind:
create_host_path: true # 自动创建日志目录
networks:
- bs-network
networks:
bs-network:
driver: bridge