修改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:
|
services:
|
||||||
php-fpm:
|
php-fpm:
|
||||||
build:
|
build:
|
||||||
context: ./docker/php
|
context: ./docker/php
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: newshop_php
|
container_name: ${PROJECT_NAME}_php
|
||||||
restart: always
|
restart: always
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway" # 支持主机名解析
|
- "host.docker.internal:host-gateway" # 支持主机名解析
|
||||||
environment:
|
environment:
|
||||||
- PHP_ENV=development
|
PHP_ENV: ${PHP_ENV:-development}
|
||||||
- APP_ENV=development
|
APP_ENV: ${APP_ENV:-development}
|
||||||
- APP_DEBUG=true
|
APP_DEBUG: ${APP_DEBUG:-true}
|
||||||
- XDEBUG_CONFIG=client_host=host.docker.internal client_port=9003
|
XDEBUG_CONFIG: ${XDEBUG_CONFIG:-client_host=host.docker.internal client_port=9003}
|
||||||
- PHP_IDE_CONFIG=serverName=docker-php
|
PHP_IDE_CONFIG: serverName=docker-php
|
||||||
ports:
|
ports:
|
||||||
- "9000:9000" # PHP-FPM
|
- "${PHP_FPM_PORT:-9000}:9000" # PHP-FPM
|
||||||
- "9003:9003" # Xdebug
|
- "${XDEBUG_POST:-9003}:9003" # Xdebug
|
||||||
volumes:
|
volumes:
|
||||||
- ./src:/var/www/html
|
- ./src:/var/www/html
|
||||||
# 更新下载源列表以加速apt-get
|
# 更新下载源列表以加速apt-get
|
||||||
@@ -27,17 +37,19 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
networks:
|
networks:
|
||||||
- newshop-net
|
- sass-platform-net
|
||||||
|
labels:
|
||||||
|
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
build:
|
build:
|
||||||
context: ./docker/nginx
|
context: ./docker/nginx
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: newshop_nginx
|
container_name: ${PROJECT_NAME}_nginx
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "${NGINX_PORT:-80}:80"
|
||||||
- "443:443"
|
- "${NGINX_SSL_PORT:-443}:443"
|
||||||
volumes:
|
volumes:
|
||||||
- ./src:/var/www/html:ro
|
- ./src:/var/www/html:ro
|
||||||
# 更新下载源列表以加速apt-get
|
# 更新下载源列表以加速apt-get
|
||||||
@@ -45,52 +57,51 @@ services:
|
|||||||
# 创建临时目录
|
# 创建临时目录
|
||||||
- /var/www/server/nginx/proxy_temp_dir
|
- /var/www/server/nginx/proxy_temp_dir
|
||||||
- /var/www/server/nginx/proxy_cache_dir
|
- /var/www/server/nginx/proxy_cache_dir
|
||||||
|
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- php-fpm
|
- php-fpm
|
||||||
networks:
|
networks:
|
||||||
- newshop-net
|
- sass-platform-net
|
||||||
|
labels:
|
||||||
|
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: mysql:5.7.44
|
image: mysql:5.7.44
|
||||||
container_name: newshop_mysql
|
container_name: ${PROJECT_NAME}_mysql
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: rootpassword
|
<<: *shared-api-env
|
||||||
MYSQL_ROOT_HOST: '%' # 允许root从任何主机连接
|
|
||||||
MYSQL_DATABASE: shop_mallnew
|
|
||||||
MYSQL_USER: shop_mallnew
|
|
||||||
MYSQL_PASSWORD: shop_mallnew
|
|
||||||
# env_file:
|
|
||||||
# - ./.docker/.env
|
|
||||||
volumes:
|
volumes:
|
||||||
- mysql_db_data:/var/lib/mysql
|
- mysql_db_data:/var/lib/mysql
|
||||||
- ./docker/mysql/init:/docker-entrypoint-initdb.d
|
- ./docker/mysql/init:/docker-entrypoint-initdb.d
|
||||||
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/custom.cnf
|
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/custom.cnf
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- ${MYSQL_PORT:-3306}:3306
|
||||||
networks:
|
networks:
|
||||||
- newshop-net
|
- sass-platform-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
command:
|
command:
|
||||||
- --character-set-server=utf8mb4
|
- --character-set-server=utf8mb4
|
||||||
- --collation-server=utf8mb4_unicode_ci
|
- --collation-server=utf8mb4_unicode_ci
|
||||||
- --innodb_buffer_pool_size=256M
|
- --innodb_buffer_pool_size=256M
|
||||||
|
labels:
|
||||||
|
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||||
|
|
||||||
# Redis 服务(可选)
|
# Redis 服务(可选)
|
||||||
redis:
|
redis:
|
||||||
image: redis:8.2
|
image: redis:8.2
|
||||||
container_name: newshop-redis
|
container_name: ${PROJECT_NAME}_redis
|
||||||
environment:
|
environment:
|
||||||
- REDIS_PASSWORD=luckyshop123!@#
|
REDIS_PASSWORD: ${REDIS_PASSWORD:-luckyshop123!@#}
|
||||||
|
REDISCLI_AUTH: ${REDIS_PASSWORD:-luckyshop123!@#}
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "${REDIS_PORT:-6379}:6379"
|
||||||
volumes:
|
volumes:
|
||||||
- redis_data:/data
|
- redis_data:/data
|
||||||
- ./docker/redis/redis.conf:/etc/redis/redis.conf
|
- ./docker/redis/redis.conf:/etc/redis/redis.conf
|
||||||
networks:
|
networks:
|
||||||
- newshop-net
|
- sass-platform-net
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
labels:
|
||||||
|
- "com.docker.compose.project.working_dir=${PROJECT_NAME}"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysql_db_data:
|
mysql_db_data:
|
||||||
@@ -98,5 +109,5 @@ volumes:
|
|||||||
xdebug_logs:
|
xdebug_logs:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
newshop-net:
|
sass-platform-net:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
Reference in New Issue
Block a user