Docker 构建PHP 镜像环境

PHP技术
426
0
0
2022-04-14

这个镜像只是用来处理 CI 流程的

是一个 CentOS7 + php73 + composer 环境

如需要构建 php 其他版本, 可修改 php73 至对应版本

php扩展支持了 sqlsrv , oracle, mongo

不需要支持 oracle 的需要删除相关代码

同级目录还有一个 oracle 文件夹, oracle文件夹下的文件

instantclient-basic-linux.x64-11.2.0.4.0.zip
instantclient-sdk-linux.x64-11.2.0.4.0.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0.zip

Dockerfile

FROM centos:7

RUN yum install -y yum-utils epel-release
RUN yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm 

RUN yum install -y zip \
        unzip \
        systemtap-sdt-devel \
        git \
        libaio

RUN curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo \
    && ACCEPT_EULA=Y yum install msodbcsql17 mssql-tools -y \
    && echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc \
    && source ~/.bashrc

COPY ./oracle /usr/local/src/

RUN cd /usr/local/src \
    && unzip instantclient-basic-linux.x64-11.2.0.4.0.zip -d /usr/local \
    && unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip -d /usr/local \
    && unzip instantclient-sqlplus-linux.x64-11.2.0.4.0.zip -d /usr/local \
    && cd /usr/local/instantclient_11_2 \
    && ln -s libclntsh.so.11.1 libclntsh.so \
    && ln -s libocci.so.11.1 libocci.so \
    && echo '/usr/local/instantclient_11_2' > /etc/ld.so.conf.d/oracle-instantclient.conf \
    && ldconfig \
    && echo 'export PATH="$PATH:/usr/local/instantclient_11_2"' >> ~/.bashrc \
    && source ~/.bashrc 

RUN yum install -y php73-php-common \
        php73-php-fpm \
        php73-php-cli \
        php73-php-bcmath \
        php73-php-gd \
        php73-php-json \
        php73-php-mbstring \
        php73-php-mcrypt \
        php73-php-mysqlnd \
        php73-php-opcache \
        php73-php-pdo \
        php73-php-pecl-crypto \
        php73-php-pecl-mcrypt \
        php73-php-pecl-geoip \
        php73-php-recode \
        php73-php-snmp \
        php73-php-soap \
        php73-php-xml \
        php73-php-pear \
        php73-php-devel \
        php73-php-pecl-mongodb \
        php73-pecl-redis \
        php73-php-sqlsrv \
    && ln -s /opt/remi/php73/root/bin/* /usr/bin/ 

RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer

RUN export PHP_DTRACE=yes \
    && pecl channel-update pecl.php.net \
    && sh -c '/bin/echo -e "instantclient,/usr/local/instantclient_11_2" | pecl install oci8-2.2.0' \
    && echo 'extension=oci8.so' >> /etc/opt/remi/php73/php.d/20-oci8.ini