配置dockerfile檔案,並安裝PHP擴充套件
1. vim dockerfile #新建dockerfile檔案
2. 寫入dockerfile配置
# PHP官方映象
FROM php:7.2-fpm
#GD庫擴充套件
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include \
&& docker-php-ext-install -j$(nproc) gd
#redis 擴充套件
RUN pecl install redis-5.2.2 && docker-php-ext-enable redis
#bcmath擴充套件
RUN docker-php-ext-install -j$(nproc) bcmath
#PDO擴充套件
RUN docker-php-ext-install pdo pdo_mysql
#mysqli擴充套件
RUN cd /usr/local/bin && ./docker-php-ext-install mysqli
#mcrypt擴充套件
RUN apt-get install libmcrypt-dev && pecl install mcrypt-1.0.1 && docker-php-ext-enable mcrypt.
3. docker build -t php:test72 . #打包映象
配置docker-compose-php.yml檔案
version: '3'
services:
nginx:
image: nginx:1.18
container_name: nginx
restart: always
volumes:
- /mydata/nginx/nginx.conf:/etc/nginx/nginx.conf #配置檔案掛載
- /mydata/nginx/html:/usr/share/nginx/html #靜態資源根目錄掛載
- /mydata/nginx/log:/var/log/nginx #日誌檔案掛載
ports:
- 80:80
phpfpm:
image: php:test #test是docker build打包的映象名稱
container_name: php72
volumes:
- /mydata/nginx/html/:/usr/share/nginx/html
ports:
- 9000:9000
啟動docker-compose
docker-compose -f docker-compose-php.yml up -d #建立容器
本作品採用《CC 協議》,轉載必須註明作者和本文連結