利用官方镜像+Dockerfile构建符合自己要求php7.4镜像
DockerFile
- apt官方源太慢时,切换apt源
- 该dockerfile支持的php额外扩展 bcmatch event exif gd mysqli iconv pcntl pdo_mysql redis sockets opcache
- 来源 php:7.4.33-fpm
FROM php:7.4.33-fpmENV TZ=Asia/ShanghaiRUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone#切换apt源 需要就放开#RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak#ADD sources.list /etc/apt/#RUN cat /etc/apt/sources.listRUN apt-get clean all && apt-get update && apt-get install -y \#部分调试工具,线上环境不需要#telnet curl vim inetutils-ping \libevent-dev pkg-config libxml2 libxml2-dev openssl libssl-dev sqlite3 \libsqlite3-dev libpng-dev libjpeg-dev libfreetype-dev \ && docker-php-ext-install pdo_mysql mysqli \ && docker-php-ext-install bcmath exif gd iconv pcntlRUN pecl install redis && docker-php-ext-enable redis \&& docker-php-ext-install sockets && docker-php-ext-enable sockets \&& pecl install event-3.0.6 && docker-php-ext-enable event \&& rm -rf /tmp/pear#安装composeRUN curl -sS https://getcomposer.org/installer | php -- \--install-dir=/usr/bin --filename=composerRUN chmod a+x /usr/bin/composer \ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/EXPOSE 9000
同级目录的 sources.list文件,需要切换apt源时使用
#http://mirrors.163.com/debian/为软件源也可以为其他的 bullseye为版本代号 main non-free contrib区别如下deb http://mirrors.163.com/debian/ bullseye main non-free contribdeb http://mirrors.163.com/debian/ bullseye-updates main non-free contribdeb http://mirrors.163.com/debian/ bullseye-backports main non-free contribdeb-src http://mirrors.163.com/debian/ bullseye main non-free contribdeb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contribdeb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib#deb http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib#deb http://mirrors.ustc.edu.cn/debian-security/ bullseye/updates main non-free contrib#deb-src http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib#deb-src http://mirrors.ustc.edu.cn/debian-security/ bullseye/updates main non-free contribdeb http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contribdeb-src http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib
Docker-compose
- 挂载文件php.ini php-fpm.conf
- stdin_open与 tty 用于执行常驻脚本
- 构建后镜像名称 php:7.4-local
- fpm reload 宿主机指令: docker exec php kill -USR2 1
- cli 宿主机指令 docker exec php php ${WWW_DIR}/cli.php
- .env配置 WWW_DIR挂载项目路径
- docker-compose up 首次启动会构建镜像
version: "3"networks: webnet: driver: bridgeservices: php: build: ./php image: php:7.4-local container_name: php restart: always expose: - 9000 stdin_open: true tty: true environment: - TZ=Asia/Shanghai volumes: - ${WWW_DIR}:/www - ./php/etc/php.ini:/usr/local/etc/php/php.ini - ./php/etc/php-fpm.conf:/usr/local/etc/php-fpm.d/www.conf networks: - webnet
来源地址:https://blog.csdn.net/u011105165/article/details/128133891