Commit 59413f0f by 纪相明

增加docker环境支持.

parent f893d5ba
...@@ -51,4 +51,17 @@ WECHAT_MINI_PROGRAM_SECRET= ...@@ -51,4 +51,17 @@ WECHAT_MINI_PROGRAM_SECRET=
# 短信 # 短信
SMS_USERNAME=tzthy SMS_USERNAME=tzthy
SMS_PASSWORD= SMS_PASSWORD=
\ No newline at end of file
# docker-compose 的相关环境变量
COMPOSE_PROJECT_NAME=tzt-admin
TZ=Asia/Shanghai
DOCKER_IP_PREFIX=172.16.54
# PHP容器执行权限
PHP_FPM_UID=33
# 是否使用Docker版本MySQL
ENABLE_MYSQL_SERVICE=0
MYSQL_DATA_DIR=./runtime/mysql
# 是否使用Docker版本Redis
ENABLE_REDIS_SERVICE=0
REDIS_DATA_DIR=./runtime/redis
...@@ -19,3 +19,4 @@ yarn-error.log ...@@ -19,3 +19,4 @@ yarn-error.log
/.vscode /.vscode
/public/uploads /public/uploads
.DS_Store .DS_Store
/runtime
networks:
net:
ipam:
driver: default
config:
- subnet: ${DOCKER_IP_PREFIX}.0/24
services:
mysql:
restart: always
build: ./docker/mysql
volumes:
- ${MYSQL_DATA_DIR}:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
- TZ=${TZ}
deploy:
replicas: ${ENABLE_MYSQL_SERVICE}
networks:
net:
ipv4_address: ${DOCKER_IP_PREFIX}.2
redis:
restart: always
build: ./docker/redis
volumes:
- ${REDIS_DATA_DIR}:/data
environment:
- TZ=${TZ}
deploy:
replicas: ${ENABLE_REDIS_SERVICE}
networks:
net:
ipv4_address: ${DOCKER_IP_PREFIX}.3
php-fpm:
restart: always
build:
context: ./docker/php
volumes:
- .:/var/www
environment:
- TZ=${TZ}
# - XDEBUG_CONFIG=client_host=${DOCKER_IP_PREFIX}.1
user: "${PHP_FPM_UID}"
networks:
net:
ipv4_address: ${DOCKER_IP_PREFIX}.4
nginx:
restart: always
build: ./docker/nginx
volumes:
- .:/var/www
depends_on:
- php-fpm
environment:
- TZ=${TZ}
entrypoint:
[ "wait-for-it", "-s", "php-fpm:9000", "--", "nginx", "-g", "daemon off;" ]
networks:
net:
ipv4_address: ${DOCKER_IP_PREFIX}.5
FROM mysql:8.0.35
COPY mysql.conf.d /etc/mysql/mysql.conf.d
[client]
default-character-set=utf8mb4
# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
datadir = /data
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-time-zone=+08:00
explicit_defaults_for_timestamp=true
ssl=0
max_allowed_packet = 1G
# 导入大sql参数
#innodb_buffer_pool_size = 4G
#innodb_log_buffer_size = 256M
#innodb_log_file_size = 1G
#innodb_write_io_threads = 16
#innodb_flush_log_at_trx_commit = 0
FROM nginx:1.21.5
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install wait-for-it -y --no-install-recommends && \
apt-get autoremove -y && \
apt-get clean -y && \
apt-get autoclean -y
COPY nginx.conf /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
port_in_redirect off;
absolute_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
proxy_pass_request_headers on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
disable_symlinks off;
server_tokens off;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
client_max_body_size 500m;
client_body_buffer_size 500m;
server {
listen 80;
index index.php index.html index.htm default.php default.htm default.html;
root /var/www/public;
proxy_ignore_client_abort on;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
location /admin {
try_files $uri $uri/ /admin/index.php$is_args$query_string;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param SERVER_NAME $host;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) {
return 404;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|svg)$ {
expires 30d;
error_log off;
access_log off;
}
location ~ .*\.(js|css|json)$ {
expires 30d;
error_log off;
access_log off;
}
}
}
FROM php:8.1.11-fpm
# basic
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install wait-for-it --no-install-recommends -y
# `exif extension`
RUN docker-php-ext-configure exif \
&& docker-php-ext-install -j $(nproc) exif
# `zip extension`
RUN apt-get install -y --no-install-recommends libzip-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install -j $(nproc) zip
# `bcmath extension`
RUN docker-php-ext-configure bcmath \
&& docker-php-ext-install -j $(nproc) bcmath
# `pdo_mysql extension`
RUN docker-php-ext-configure pdo_mysql \
&& docker-php-ext-install -j $(nproc) pdo_mysql
# `mysqli extension`
RUN docker-php-ext-configure mysqli \
&& docker-php-ext-install -j $(nproc) mysqli
# `redis extension`
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
# `composer`
RUN curl https://mirrors.aliyun.com/composer/composer.phar -o /bin/composer \
&& chmod +x /bin/composer
# `gd extension`
RUN apt-get install -y --no-install-recommends \
libwebp-dev \
libjpeg-dev \
libpng-dev \
libxpm-dev \
libfreetype6-dev
RUN docker-php-ext-configure gd \
--enable-gd \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype \
&& docker-php-ext-install -j $(nproc) gd
# `mysqli extension`
RUN docker-php-ext-configure sockets \
&& docker-php-ext-install -j $(nproc) sockets
# `opcache`
RUN docker-php-ext-configure opcache
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini
# `php.ini`
COPY php.ini /usr/local/etc/php/php.ini
# `xdebug`
#RUN pecl install xdebug
#COPY debug.ini /usr/local/etc/php/conf.d/xdebug.ini
# `crontab`
# `echo "" >> /etc/crontab` 确保最后一行有一个空行, 否则可能无法执行
RUN apt-get install cron -y --no-install-recommends
COPY crontab /etc/crontab
RUN chown root:root /etc/crontab \
&& chmod 0644 /etc/crontab
# clean
RUN apt-get clean -y \
&& apt-get autoclean -y \
&& apt-get autoremove -y
COPY php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf
RUN chmod 777 /tmp -R
RUN mkdir /var/log/php-fpm && chown 33.33 /var/log/php-fpm -R
WORKDIR /var/www
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
TZ=Asia/Shanghai
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
#
# 每分钟检测一次服务是否正常运行
zend_extension=xdebug
xdebug.mode=debug
xdebug.client_host=172.16.41.1
[opcache]
opcache.enable=1
opcache.enable_cli=1
; 共享内存大小
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=2
opcache.fast_shutdown=1
\ No newline at end of file
FROM redis
COPY redis.conf /etc/redis.conf
CMD [ "redis-server", "/etc/redis.conf" ]
\ No newline at end of file
daemonize no
timeout 0
databases 16
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment