修改docker相关配置,支持通过.env文件传入变量
This commit is contained in:
24
.env.example
Normal file
24
.env.example
Normal file
@@ -0,0 +1,24 @@
|
||||
# 项目配置, 请根据实际情况修改
|
||||
PROJECT_NAME=newshop
|
||||
|
||||
# PHP/PHP-FPM 配置
|
||||
PHP_VERSION=7.4
|
||||
PHP_FPM_VERSION=7.4-fpm
|
||||
PHP_FPM_PORT=9000
|
||||
XDEBUG_POST=9003
|
||||
|
||||
# 数据库配置
|
||||
MYSQL_ROOT_HOST=%
|
||||
MYSQL_DATABASE=shop_mallnew
|
||||
MYSQL_USER=shop_mallnew
|
||||
MYSQL_PASSWORD=shop_mallnew
|
||||
MYSQL_PORT=3306
|
||||
|
||||
# Redis 配置
|
||||
REDIS_PASSWORD=luckyshop123!@#
|
||||
REDIS_PORT=6379
|
||||
|
||||
# Nginx 配置
|
||||
NGINX_PORT=80
|
||||
NGINX_SSL_PORT=443
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
x-shared-env: &shared-api-env
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
|
||||
MYSQL_ROOT_HOST: ${MYSQL_ROOT_HOST:-'%'} # 允许root从任何主机连接
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:-shop_mallnew}
|
||||
MYSQL_USER: ${MYSQL_USER:-shop_mallnew}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-shop_mallnew}
|
||||
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:-luckyshop123!@#}
|
||||
REDIS_PORT: ${REDIS_PORT:-6379}
|
||||
|
||||
# 将服务归类到目录 A 中
|
||||
services:
|
||||
php-fpm:
|
||||
build:
|
||||
context: ./docker/php
|
||||
dockerfile: Dockerfile
|
||||
container_name: newshop_php
|
||||
container_name: ${PROJECT_NAME}_php
|
||||
restart: always
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway" # 支持主机名解析
|
||||
environment:
|
||||
- PHP_ENV=development
|
||||
- APP_ENV=development
|
||||
- APP_DEBUG=true
|
||||
- XDEBUG_CONFIG=client_host=host.docker.internal client_port=9003
|
||||
- PHP_IDE_CONFIG=serverName=docker-php
|
||||
PHP_ENV: ${PHP_ENV:-development}
|
||||
APP_ENV: ${APP_ENV:-development}
|
||||
APP_DEBUG: ${APP_DEBUG:-true}
|
||||
XDEBUG_CONFIG: ${XDEBUG_CONFIG:-client_host=host.docker.internal client_port=9003}
|
||||
PHP_IDE_CONFIG: serverName=docker-php
|
||||
ports:
|
||||
- "9000:9000" # PHP-FPM
|
||||
- "9003:9003" # Xdebug
|
||||
- "${PHP_FPM_PORT:-9000}:9000" # PHP-FPM
|
||||
- "${XDEBUG_POST:-9003}:9003" # Xdebug
|
||||
volumes:
|
||||
- ./src:/var/www/html
|
||||
# 更新下载源列表以加速apt-get
|
||||
@@ -27,17 +37,19 @@ services:
|
||||
depends_on:
|
||||
- db
|
||||
networks:
|
||||
- newshop-net
|
||||
- sass-platform-net
|
||||
labels:
|
||||
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||
|
||||
nginx:
|
||||
build:
|
||||
context: ./docker/nginx
|
||||
dockerfile: Dockerfile
|
||||
container_name: newshop_nginx
|
||||
container_name: ${PROJECT_NAME}_nginx
|
||||
restart: always
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- "${NGINX_PORT:-80}:80"
|
||||
- "${NGINX_SSL_PORT:-443}:443"
|
||||
volumes:
|
||||
- ./src:/var/www/html:ro
|
||||
# 更新下载源列表以加速apt-get
|
||||
@@ -45,52 +57,51 @@ services:
|
||||
# 创建临时目录
|
||||
- /var/www/server/nginx/proxy_temp_dir
|
||||
- /var/www/server/nginx/proxy_cache_dir
|
||||
|
||||
|
||||
depends_on:
|
||||
- php-fpm
|
||||
networks:
|
||||
- newshop-net
|
||||
- sass-platform-net
|
||||
labels:
|
||||
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||
|
||||
db:
|
||||
image: mysql:5.7.44
|
||||
container_name: newshop_mysql
|
||||
container_name: ${PROJECT_NAME}_mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: rootpassword
|
||||
MYSQL_ROOT_HOST: '%' # 允许root从任何主机连接
|
||||
MYSQL_DATABASE: shop_mallnew
|
||||
MYSQL_USER: shop_mallnew
|
||||
MYSQL_PASSWORD: shop_mallnew
|
||||
# env_file:
|
||||
# - ./.docker/.env
|
||||
<<: *shared-api-env
|
||||
volumes:
|
||||
- mysql_db_data:/var/lib/mysql
|
||||
- ./docker/mysql/init:/docker-entrypoint-initdb.d
|
||||
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/custom.cnf
|
||||
ports:
|
||||
- "3306:3306"
|
||||
- ${MYSQL_PORT:-3306}:3306
|
||||
networks:
|
||||
- newshop-net
|
||||
- sass-platform-net
|
||||
restart: unless-stopped
|
||||
command:
|
||||
- --character-set-server=utf8mb4
|
||||
- --collation-server=utf8mb4_unicode_ci
|
||||
- --innodb_buffer_pool_size=256M
|
||||
labels:
|
||||
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||
|
||||
# Redis 服务(可选)
|
||||
redis:
|
||||
image: redis:8.2
|
||||
container_name: newshop-redis
|
||||
container_name: ${PROJECT_NAME}_redis
|
||||
environment:
|
||||
- REDIS_PASSWORD=luckyshop123!@#
|
||||
REDIS_PASSWORD: ${REDIS_PASSWORD:-luckyshop123!@#}
|
||||
REDISCLI_AUTH: ${REDIS_PASSWORD:-luckyshop123!@#}
|
||||
ports:
|
||||
- "6379:6379"
|
||||
- "${REDIS_PORT:-6379}:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
- ./docker/redis/redis.conf:/etc/redis/redis.conf
|
||||
networks:
|
||||
- newshop-net
|
||||
- sass-platform-net
|
||||
restart: unless-stopped
|
||||
labels:
|
||||
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||
|
||||
volumes:
|
||||
mysql_db_data:
|
||||
@@ -98,5 +109,5 @@ volumes:
|
||||
xdebug_logs:
|
||||
|
||||
networks:
|
||||
newshop-net:
|
||||
sass-platform-net:
|
||||
driver: bridge
|
||||
Reference in New Issue
Block a user