version: '3'
services:
php74:
build:
context: ./
dockerfile: DockerPHP74
args:
PHP_VERSION: 7.4
container_name: phpfpm74
volumes:
- ./www/php74/:/var/www/html/
- ./phpconf/php74/:/usr/local/etc/
privileged: true
environment:
TZ: Asia/Shanghai
links:
- redis
- mysql
networks:
- back-tier
- front-tier
php73:
build:
context: ./
dockerfile: DockerPHP73
args:
PHP_VERSION: 7.3
container_name: phpfpm73
volumes:
- ./www/php73/:/var/www/html/
- ./phpconf/php73/:/usr/local/etc/
privileged: true
environment:
TZ: Asia/Shanghai
depends_on:
- redis
- mysql
links:
- redis
- mysql
networks:
- back-tier
- front-tier
redis:
image: redis
container_name: redis
environment:
TZ: Asia/Shanghai
ports:
- 6379:6379
networks:
- front-tier
nginx:
image: nginx
ports:
- 8080:80
- 8081:8081
- 8082:8082
environment:
TZ: Asia/Shanghai
depends_on:
- php73
- php74
links:
- php74
- php73
volumes:
- ./nginx/:/etc/nginx/
container_name: nginx
networks:
- front-tier
mysql:
image: mysql:5.6
ports:
- 3306:3306
container_name: mysql56
volumes:
- ./mysql/conf/:/etc/mysql/
- ./mysql/data/:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
TZ: Asia/Shanghai
networks:
- front-tier
networks:
front-tier:
driver: bridge
back-tier:
driver: bridge
ARG PHP_VERSION=7.4
FROM php:${PHP_VERSION}-fpm
ENV TZ='Asia/Shanghai'
RUN apt-get update \
&& apt-get install -y apt-utils \
&& apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzstd-dev \
&& pecl install igbinary \
&& pecl install redis \
&& docker-php-ext-enable igbinary \
&& docker-php-ext-enable redis \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install bcmath \
&& kill -USR2 1
ARG PHP_VERSION=7.3
FROM php:${PHP_VERSION}-fpm
ENV TZ='Asia/Shanghai'
RUN apt-get update \
&& apt-get install -y apt-utils \
&& apt-get install -y \
apt-utils \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libwebp-dev \
libzstd-dev \
&& docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2 \
&& docker-php-ext-install gd \
&& pecl install igbinary \
&& pecl install redis \
&& docker-php-ext-enable igbinary redis \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install bcmath \
&& kill -USR2 1
php容器内重启php-fpm方法
# php-fpm的pid就是1
kill -USR2 1
server{
listen 8081;
access_log logs/test_access.log;
error_log logs/test_error.log;
location ~ \.php$ {
# 这里的是php容器项目路径
root /var/www/html;
# 实用docker-compose中的php73、php74作为协议连接
fastcgi_pass php73:9000;
fastcgi_index index.php;
# 这里的是php容器项目路径
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /www/index.php;
include /etc/nginx/fastcgi_params;
}
}
volumes:
- ./mysql/conf/:/etc/mysql/
- ./mysql/data/:/var/lib/mysql
volumes:
- ./www/php74/:/var/www/html/
- ./phpconf/php74/:/usr/local/etc/
.........