DockerFile部署lnmp+memcached+redis+mongodb开发环境for PHP
Posted 93bok
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DockerFile部署lnmp+memcached+redis+mongodb开发环境for PHP相关的知识,希望对你有一定的参考价值。
本文源链接地址:https://www.93bok.com
1、下载基础镜像centos
docker pull centos:6
2、查看一下大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 2 months ago 195MB
3、创建文件夹存放php的Dockerfile,以及源码包等等,为后期docker-compose做准备
mkdir -p /data/docker/lnmp-test/dockerfile/php
4、创建PHP的Dockerfile
vim /data/docker/lnmp-test/dockerfile/php/Dockerfile
FROM centos:6
LABEL maintainer="[email protected]" description="PHP image"
ENV PHP_VERSION 5.6.25
COPY extensions/ /root/extensions
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 && yum install -y epel-release && rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 && CONFIG=" --prefix=/usr/local/php --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-short-tags --enable-mbstring --with-curl --enable-sockets --enable-zip --enable-pcntl --with-bz2 --enable-inline-optimization --with-openssl --with-mhash --with-mcrypt --enable-mbregex --with-pcre-regex --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-jpeg-dir --with-zlib --with-png-dir --disable-rpath --enable-bcmath" && yum install -y gcc gcc-c++ bison re2c libxml2-devel openssl-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel libmcrypt-devel unzip libmemcached-devel cyrus-sasl-devel ImageMagick-devel && groupadd www && useradd -s /sbin/nologin -M -g www www && tar -zxvf /root/extensions/php-$PHP_VERSION.tar.gz -C /root/extensions/ && cd /root/extensions/php-$PHP_VERSION && ./configure $CONFIG && make -j $(getconf _NPROCESSORS_ONLN) && make install && mkdir -p /etc/php/conf.d && cp /root/extensions/php-$PHP_VERSION/php.ini-development /etc/php/php.ini && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && sed -i ‘s|^;?pids*=s*(.+)|pid = 1|g; s|^;?listens*=s*.+|listen = 9000|g‘ /usr/local/php/etc/php-fpm.conf && sed -i ‘s|^;?error_logs*=s*(.+)|error_log = 1|g; s|^;?daemonizes*=s*.+|daemonize = no|g‘ /usr/local/php/etc/php-fpm.conf && sed -i ‘s|^;?slowlogs*=s*(.+)|slowlog = 1|g; s|^;?catch_workers_outputs*=s*.+|catch_workers_output = yes|g‘ /usr/local/php/etc/php-fpm.conf && ln -s /usr/local/php/bin/* /usr/local/bin/ && ln -s /usr/local/php/sbin/* /usr/local/sbin/ && cd /root/extensions/ && unzip igbinary-1.0.2.zip && cd igbinary-1.0.2 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && tar -zxvf libmemcached-1.0.18.tar.gz && cd libmemcached-1.0.18 && ./configure --prefix=/usr/local/libmemcached && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && unzip php-memcached-2.2.0.zip && cd php-memcached-2.2.0 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/ && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && unzip cphalcon-3.0.3.zip && cd cphalcon-3.0.3/build/php5/64bits/ && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && unzip phpredis-2.2.8.zip && cd phpredis-2.2.8 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && tar -zxvf imagick-3.1.1.tgz && cd imagick-3.1.1 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/php-$PHP_VERSION/ext/bcmath/ && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && unzip apcu-4.0.8.zip && cd apcu-4.0.8 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && cd /root/extensions/ && tar -zxvf mongodb-1.3.2.tgz && cd mongodb-1.3.2 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j $(getconf _NPROCESSORS_ONLN) && make install && rm -rf /root/extensions/ && yum clean all
EXPOSE 9000
CMD ["/usr/local/php/sbin/php-fpm", "-F", "-c", "/etc/php/php.ini"]
5、把php源码包和扩展包上传到/data/docker/lnmp-test/dockerfile/php/目录下
6、创建镜像
cd /data/docker/lnmp-test/dockerfile/php/
docker build -t centos6:php .
7、查看镜像大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6 php 1d483171ba08 4 seconds ago 734MB
centos 6 70b5d81549ec 2 months ago 195MB
8、启动容器测试是否成功
docker run -d -p 9000:9000 --name php centos6:php
9、宿主机开启防火墙9000端口
firewall-cmd --add-port=9000/tcp --permanent
systemctl restart firewalld
以上是关于DockerFile部署lnmp+memcached+redis+mongodb开发环境for PHP的主要内容,如果未能解决你的问题,请参考以下文章
DockerFile部署lnmp+memcached+redis+mongodb开发环境for MySQL
DockerFile部署lnmp+memcached+redis+mongodb开发环境for Redis
DockerFile部署lnmp+memcached+redis+mongodb开发环境for Nginx