关于docker:Dockerfile搭建PHP8镜像dockercompose搭建LNMP环境

22次阅读

共计 2454 个字符,预计需要花费 7 分钟才能阅读完成。

应用 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 扩大、及其他扩大

正文完
 0