```
version: '3'
services:
# mysql容器
mysql:
container_name: lnmp_mysql
image: mysql:5.7
restart: always
ports:
- 33061:3306
volumes:
- ./mysql/my.cnf:/etc/mysql/my.cnf
- ./mysql/data:/var/lib/mysql #挂载数据目录到本地
- ./mysql/log:/var/log/mysql
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=256M
--default-authentication-plugin=mysql_native_password
--sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: '123456'
MYSQL_DATABASE: 'docker_bjl_mysql'
MYSQL_USER: 'docker_bjl_mysql'
MYSQL_PASSWORD: '123456'
networks:
- single
# redis容器
redis:
container_name: lnmp_redis
image: redis:7.0
restart: always
# image: daocloud.io/library/redis:6.0.5-alpine
# image: redis:5.0
ports:
- 5000:6379
volumes:
# - ./redis/data:/data #挂载数据目录到本地
- ./redis/redis.conf:/etc/redis/redis.conf
- ./redis/logs:/logs
command: [ "redis-server","/etc/redis/redis.conf" ]
networks:
- single
# privileged:true【使用该参数,container内的root拥有真正的root权限。否则,container内的root只是外部的一个普通用户权限】
# mongoDb容器
mongo:
container_name: lnmp_mongo
image: mongo:4.4.6
restart: always
command: mongod
logging:
driver: 'json-file'
options:
max-size: '10g'
volumes:
- ./mongo/config/mongod.conf:/etc/mongod.conf:rw
- ./mongo/configdb:/data/configdb:rw
- ./mongo/db:/data/db:rw
ports:
- 27017:27017
environment:
TZ: Asia/Shanghai
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 123456
MONGO_INITDB_DATABASE: bjl
networks:
- single
# rabbitmq容器
rabbitmq:
container_name: rabbitmq # 容器名为rabbitmq
image: rabbitmq:3.8-management # 镜像`rabbitmq:3.8-management` 【 注:该版本包含了web控制页面 】
restart: always # 指定容器退出后的重启策略为始终重启
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
RABBITMQ_DEFAULT_USER: admin # rabbitmq 的登录账户
RABBITMQ_DEFAULT_PASS: admin # rabbitmq 的登录密码
ports: # 映射端口
- "5672:5672"
- "15672:15672"
volumes:
- ./rabbitmq/addplugins:/addplugins # Mq插件:rabbitmq_delayed_message_exchange-3.8.0.ez
networks:
- single
# nginx容器
nginx:
container_name: lnmp_nginx
image: nginx
ports:
- 8080:80
- 4000:443
working_dir: /wwwroot/wwwroot
volumes_from:
- php7.4 #继承phpfpm挂载目录
- php8.1 #继承phpfpm挂载目录
volumes:
- ./html:/usr/share/nginx/html
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/logs:/var/log/nginx
depends_on:
- php7.4
- php8.1
restart: always
logging:
driver: 'json-file'
options:
max-size: '10g'
networks:
- other
- single
# php7.4容器
php7.4:
container_name: lnmp_php74
build:
context: ./php/php74 # dockerfile文件路径
dockerfile: Dockerfile # 指定dockerfile文件名称
expose:
- 9000
ports:
- "8000:9000"
links:
- mysql:mysql
- redis:redis
- mongo:mongo
- rabbitmq:rabbitmq
environment:
TZ: Asia/Shanghai
volumes:
- ./wwwroot:/wwwroot #程序运行目录
- ./php/php74/php.ini:/usr/local/etc/php/php74/php.ini:rw
restart: always
logging:
driver: 'json-file'
options:
max-size: '10g'
networks:
- other
- single
# php8.1容器
php8.1:
container_name: lnmp_php81
image: registry.cn-beijing.aliyuncs.com/hz-kuaiwan/php-laravel9.5:php.8.1
expose:
- 9000
ports:
- "10000:9000"
links:
- mysql:mysql
- redis:redis
- mongo:mongo
- rabbitmq:rabbitmq
environment:
TZ: Asia/Shanghai
volumes:
- "./wwwroot:/wwwroot"
- "./php/php81:/usr/local/etc/php"
- "./php/php81/php.ini:/etc/php8/php.ini"
- "./php/php81/php-fpm.d:/usr/local/etc/php-fpm.d"
restart: always
logging:
driver: 'json-file'
options:
max-size: '10g'
networks:
- other
- single
# Prometheus容器
prometheus:
container_name: lnmp_prometheus
image: prom/prometheus:v2.30.3
restart: always
ports:
- 11000:9090
volumes:
- ./prometheus:/etc/prometheus # 这里指定Prometheus的配置文件和规则目录
command:
- '--config.file=/etc/prometheus/prometheus.yml'
networks:
- single
clickhouse:
container_name: clickhouse
image: yandex/clickhouse-server
ports:
- "8123:8123" # ClickHouse HTTP 端口
- "12000:9000" # ClickHouse Native 客户端端口
volumes:
- ./clickhouse/data:/var/lib/clickhouse # ClickHouse 数据目录
- ./clickhouse/log/:/var/log/clickhouse-server/
environment:
- TZ=Asia/Shanghai
- CLICKHOUSE_PASSWORD=123456 # 设置 ClickHouse 密码
ulimits:
nofile: #设置容器的文件句柄限制
soft: 262144
hard: 262144
networks:
- single
# 网络层定义[lnmp]
networks:
# lnmp
other:
driver: bridge
single:
driver: bridge
```