基于Alpine构建php7.0.27镜像的dockerfile

[[email protected] alpine_php70]#cat run.sh 
#!/bin/bash
/production/server/php/sbin/php-fpm &
/usr/sbin/sshd -D
[[email protected] alpine_php70]#cat php-fpm.conf
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log

[www]
user = www
group = www
listen = 127.0.0.1:9000

pm = static
pm.max_children = 32
;pm.start_servers = 2
;pm.min_spare_servers = 1
;pm.max_spare_servers = 3

pm.max_requests = 8192

pm.status_path = /php-fpm_status
ping.path = /ping

request_terminate_timeout = 10
[[email protected] alpine_php70]#cat Dockerfile
FROM alpine:3.8
MAINTAINER tech-ops
COPY run.sh /
RUN cd / && \
    wget http://101.96.10.63/cn2.php.net/distributions/php-7.0.27.tar.gz && \
    wget https://curl.haxx.se/download/curl-7.20.0.tar.gz && \
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
    apk update  && \
    apk add build-base shadow openssh bash libxml2-dev openssl-dev libjpeg-turbo-dev libpng-dev libxpm-dev freetype-dev gd-dev gettext-dev libmcrypt-dev binutils && \
    addgroup www  && \
    adduser -G www -D -s /sbin/nologin www  && \
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ""  && \
    ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""  && \
    ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ""  && \
    ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""  && \
    usermod -s /bin/bash root  && \
    sed -i 's@#PermitRootLogin prohibit-password@PermitRootLogin yes@' /etc/ssh/sshd_config  && \
    echo -e  "huanqiu.com\nhuanqiu.com" | passwd root  && \
    cd / && tar -zxf curl-7.20.0.tar.gz && cd curl-7.20.0 && ./configure --prefix=/usr/local/curl --disable-ipv6 && \
    make && make install && \
    cd / && tar -zxf php-7.0.27.tar.gz && cd php-7.0.27 && ./configure \
    --prefix=/production/server/php \
    --with-config-file-path=/production/server/php/etc \
    --with-config-file-scan-dir=/production/server/php/etc/php.d \
    --disable-ipv6 \
    --enable-bcmath \
    --enable-calendar \
    --enable-exif \
    --enable-fpm \
    --with-fpm-user=www \
    --with-fpm-group=www \
    --enable-ftp \
    --enable-gd-jis-conv \
    --enable-gd-native-ttf \
    --enable-inline-optimization \
    --enable-mbregex \
    --enable-mbstring \
    --enable-mysqlnd \
    --enable-opcache \
    --enable-pcntl \
    --enable-shmop \
    --enable-soap \
    --enable-sockets \
    --enable-static \
    --enable-sysvsem \
    --enable-wddx \
    --enable-xml \
    --with-curl=/usr/local/curl \
    --with-gd=/usr \
    --with-jpeg-dir \
    --with-freetype-dir \
    --with-xpm-dir \
    --with-png-dir \
    --with-gettext \
    --with-iconv \
    --with-libxml-dir=/usr \
    --with-mcrypt \
    --with-mhash \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-openssl \
    --with-xmlrpc \
    --with-zlib \
    --without-pear \
    --disable-debug \
    --disable-phpdbg && \
    make && make install && \
    echo "PATH=\$PATH:/production/server/php/bin" >> /root/.bashrc && \
    echo "PATH=\$PATH:/production/server/php/sbin" >> /root/.bashrc && \
    echo "export rm='rm -i'" >> /root/.bashrc && \
    echo "export cp='cp -i'" >> /root/.bashrc && \
    strip /production/server/php/bin/php && \
    strip /production/server/php/bin/php-cgi && \
    strip /production/server/php/sbin/php-fpm && \
    apk del build-base shadow binutils && \
    rm -rf /curl-7.20.0.tar.gz /curl-7.20.0 /php-7.0.27.tar.gz /php-7.0.27 /var/cache/apk/* && \
    chmod +x /run.sh
VOLUME ["/production/server/php/etc/","/production/server/php/etc/php-fpm.d"]
COPY php-fpm.conf /production/server/php/etc/
EXPOSE 22 9000
ENTRYPOINT ["/run.sh"]
docker build -t  alpine_php70:v1 .

 

FAQ:

Q1:configure: error: xml2-config not found. Please check your libxml2 installation.
#apk add libxml2-dev

Q2:configure: error: Cannot find OpenSSL's
#apk add openssl-dev 

Q3:./configure: ./configure.lineno: line 24844: can't open curl-dir: no such file
checking for cURL 7.10.5 or greater... ./configure: ./configure.lineno: line 24844: curl-config: not found
configure: error: cURL version 7.10.5 or later is required to compile php with cURL support

#cd / && wget https://curl.haxx.se/download/curl-7.20.0.tar.gz
#tar zxvf curl-7.20.0.tar.gz
#cd curl-7.20.0
#./configure --prefix=/usr/local/curl && make & make install

Q4:If configure fails try --with-webp-dir=


configure: error: jpeglib.h not found.
#apk add libjpeg-turbo-dev

Q5:configure: error: png.h not found.
#apk add libpng-dev

Q6:configure: error: freetype-config not found
#apk add freetype-dev

Q7:configure: error: Cannot locate header file libintl.h
#apk add gettext-dev

Q8:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
#apk add libmcrypt-dev

Q9:configure: error: Unable to find gd.h
apk add gd-dev

Q10:编译出来的php各个可执行文件太大,用strip缩小,strip简单的说就是给文件脱掉外衣,具体就是从特定文件中剥掉一些符号信息和调试信息,使文件变小。使用strip工具需要安装binutils。

你可能感兴趣的:(DOCKER)