dockerfile 制作自定义的nginx+php
dockerfile 准备
[root@centos-7 nginx10+php56]# cat dockerfile
FROM centos:7
MAINTAINER lintianlai "lintianlai@ylwl.cn"
# 拷贝nginx php 组件到容器
ADD nginx-1.10.0.tar.gz /usr/local/src
ADD php-5.6-21.tar.gz /usr/local/src
# 安装依赖包
RUN yum makecache
RUN yum -y install epel-release
RUN yum -y install php-fpm php php-gd php-mysql php-mbstring php-xml php-mcrypt php-imap php-odbc php-pear php-xmlrpc
RUN yum -y install gcc gcc-c++ net-snmp net-snmp-devel curl-devel perl-DBI libxml2 libxml2-devel openssl-devel libpng-devel freetype-devel libmcrypt libmcrypt-devel cmake bzip2-libs bzip2-devel libjpeg libjpeg-devel libxslt libxslt-devel gd gd-devel make cmake libtool-ltdl-devel ncurses-devel bison.x86_64 net-tools
# 编译安装nginx-1.10.0
WORKDIR /usr/local/src/nginx-1.10.0
RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install
# 编译安装php-5.6.21
WORKDIR /usr/local/src/php-5.6.21
RUN ./configure --with-mysql --enable-fpm --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-gettext --with-freetype-dir --with-iconv --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-soap --enable-mbstring=all --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --with-snmp --with-openssl --with-mysqli --enable-pdo --with-pdo-mysql && make && make install
RUN cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
# 暴露80,9000端口
EXPOSE 80/tcp 9000/tcp
#CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
# 容器运行时要启动的服务,注意需要有一个是在前台运行的进程,容器才不会退出。
CMD php-fpm && /usr/local/nginx/sbin/nginx -g "daemon off;"
dockerfile 和软件
[root@centos-7 nginx10+php56]# ls /root/docker_images/nginx10+php56
dockerfile nginx-1.10.0.tar.gz php-5.6-21.tar.gz
启动并进入容器
[root@centos-7 nginx10+php56]# docker run -dit --name nginx-php -p 8008:80 -p 9009:9000 nginx10-php56
[root@faa0779055d5 php-5.6.21]# ps -ef|grep nginx
root 1 0 0 16:29 pts/0 00:00:00 /bin/sh -c php-fpm && /usr/local/nginx/sbin/nginx -g "daemon off;"
root 10 1 0 16:29 pts/0 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -g daemon off;
nginx 11 10 0 16:29 pts/0 00:00:00 nginx: worker process
root 28 12 0 16:30 pts/1 00:00:00 grep --color=auto nginx
[root@faa0779055d5 php-5.6.21]# ps -ef|grep php
root 1 0 0 16:29 pts/0 00:00:00 /bin/sh -c php-fpm && /usr/local/nginx/sbin/nginx -g "daemon off;"
root 7 1 0 16:29 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
nobody 8 7 0 16:29 ? 00:00:00 php-fpm: pool www
nobody 9 7 0 16:29 ? 00:00:00 php-fpm: pool www
root 30 12 0 16:30 pts/1 00:00:00 grep --color=auto php