应用Dockerfile搭建PHP8镜像
编写Dockerfile
vim Dockerfile
FROM php:8.1.0RC5-zts-buster
MAINTAINER itxiaoma <tlxma@163.com>
#buster是基于Debian Linux发行的一个版本,像PHP、Python之类的语言都会应用这个版本的Debian搭建Docker根底镜像。
#docker中php扩大装置形式
#1、PHP源码文件目录自带扩大 docker-php-ext-install间接装置
#2、pecl扩大 因为一些扩大不蕴含在PHP源码文件中,PHP 的扩大库仓库中存在。用 pecl install 装置扩大,再用 docker-php-ext-enable 命令 启用扩大
#3、其余扩大 一些既不在 PHP 源码包,也不再 PECL 扩大仓库中的扩大,能够通过下载扩大程序源码,编译装置的形式装置
#redis扩大 仓库地址 https://pecl.php.net/package/redis
ENV PHPREDIS_VERSION 5.3.4
#memcached扩大 仓库地址 https://pecl.php.net/package/memcached
ENV MEMCACHED_VERSION 3.1.5
#mongodb扩大 https://pecl.php.net/package/mongodb
ENV MONGODB_VERSION 1.11.1
# 设置工夫
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
# 扩大依赖
RUN apt-get update \
&& apt-get install -y \
vim \
curl \
wget \
git \
zip \
libz-dev \
libssl-dev \
libnghttp2-dev \
libpcre3-dev \
libmemcached-dev \
zlib1g-dev \
&& apt-get clean \
&& apt-get autoremove
# Composer装置
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
&& composer self-update --clean-backups
# Mysqli 扩大 自带 间接装置即可(以后数据库应用的mysqli查问的)
RUN docker-php-ext-install mysqli
# PDO 扩大 自带 间接装置即可
RUN docker-php-ext-install pdo_mysql
# Bcmath 扩大 自带 间接装置即可
RUN docker-php-ext-install bcmath
# Redis 扩大下载 pecl本地装置 开启扩大
RUN wget http://pecl.php.net/get/redis-${PHPREDIS_VERSION}.tgz -O /tmp/redis.tgz \
&& pecl install /tmp/redis.tgz \
&& rm -rf /tmp/redis.tgz \
&& docker-php-ext-enable redis
# memcached 扩大下载 pecl本地装置 开启扩大 后面曾经通过 apt-get装置了libmemcached-dev依赖
RUN wget http://pecl.php.net/get/memcached-${MEMCACHED_VERSION}.tgz -O /tmp/memcached.tgz \
&& pecl install /tmp/memcached.tgz \
&& rm -rf /tmp/memcached.tgz \
&& docker-php-ext-enable memcached
# mongodb 扩大下载 pecl本地装置 开启扩大 后面曾经通过
RUN wget http://pecl.php.net/get/mongodb-${MONGODB_VERSION}.tgz -O /tmp/mongodb.tgz \
&& pecl install /tmp/mongodb.tgz \
&& rm -rf /tmp/mongodb.tgz \
&& docker-php-ext-enable mongodb
提交镜像
docker build -f Dockerfile -t itxiaoma/php8:1.0 .
docker login -u itxiaoma
docker push itxiaoma/php8:1.0
应用docker-compose搭建LNMP环境
编写docker-compose文件
vim docker-compose.yml
version: '3.5'
services:
nginx:
image: nginx:alpine
restart: always
volumes:
- ./config/nginx:/etc/nginx/conf.d
- ./logs/nginx:/var/log/nginx
- ./workspace:/workspace
ports:
- 80:80
- 443:443
php:
image: itxiaoma/php8:1.0
restart: always
volumes:
- ./workspace:/workspace
stdin_open: true
tty: true
dbm:
image: mysql:8.0.26
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: xxx
volumes:
- './storage/mysql:/var/lib/mysql'
ports:
- 3306:3306
执行
docker-compose up
参考资料:通过docker自定义装置php7.x并且装置源码扩大、pecl扩大、及其他扩大
发表回复