# One: Environment preparation
centos7.4 and well-built Docker
[Email protected] ~]# cat/etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[Email protected] ~]# docker-v
Docker version 17.03.2-ce, build f5ec1e2
# Two: Build the image of Nginx and PHP
1.nginx
Create a base image
[Email protected]/]# vim Dockerfile
From CentOS
Maintainer liuning
Centos-base.repo.bak
RUN Mv/etc/yum.repos.d/centos-base.repo/etc/yum.repos.d/centos-base.repo.bak
/etc/yum.repos.d
COPY Centos7-base-163.repo/etc/yum.repos.d/centos7-base-163.repo
COPY epel-release-latest-7.noarch.rpm/etc/yum.repos.d/
workdir/etc/yum.repos.d/
RUN Yum install-y epel-release-latest-7.noarch.rpm
RUN Yum Clean All
RUN Yum install-y gcc gcc-c++ glibc make autoconf OpenSSL openssl-devel ntpdate crontabs
RUN Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime
Generate base image
[email protected]/]# Docker build-t Centos_init.
Create the Nginx folder under the root directory and enter
[Email protected]/]# mkdir NGINX;CD nginx
Writing Nginx's Dockerfile
[Email protected] nginx]# vim Dockerfile
From Centos_init
Maintainer liuning
RUN useradd-m-s/sbin/nologin www
ADD NGINX-1.8.1.TAR.GZ/USR/LOCAL/SRC
RUN Yum install libxslt-devel-y gd gd-devel GeoIP geoip-devel pcre pcre-devel
workdir/usr/local/src/nginx-1.8.1
RUN./configure--user=www--group=www--prefix=/usr/local/nginx--with-file-aio--with-ipv6--with-http_ssl_module-- With-http_spdy_module--with-http_realip_module--with-http_addition_module--with-http_xslt_module--with-http_ Image_filter_module--with-http_geoip_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
COPY nginx.conf/usr/local/nginx/conf/nginx.conf
COPY Fastcgi_params/usr/local/nginx/conf/fastcgi_params
RUN Mkdir/usr/local/nginx/conf/vhost
COPY www.conf/usr/local/nginx/conf/vhost/www.conf
EXPOSE 80
CMD ["/usr/local/nginx/sbin/nginx", "-G", "daemon off;"]
Get the files you need from GitHub
Https://github.com/jsonhc/docker_project/tree/master/docker_dockerfile/lnmp
These files are in the final directory
[[email protected] nginx]# ls
Dockerfile fastcgi_params nginx-1.8.1.tar.gz nginx.conf www.conf
Building an Nginx image
[email protected] nginx]# Docker build-t Nignx.
See if the build was successful
[email protected] nginx]# Docker Images | grep nginx
Nginx latest f453aeaced4a about an hour ago 583 MB
2.php
Create a PHP folder in the root directory and enter
[Email protected]/]# mkdir php;cd php
Writing dockerfile files
[[email protected] PHP] #vim Dockerfile
From Centos_init
Maintainer liuning
ADD LIBMCRYPT-2.5.7.TAR.GZ/USR/LOCAL/SRC
workdir/usr/local/src/libmcrypt-2.5.7
RUN./configure && make && make install
ADD PHP-5.6.30.TAR.BZ2/USR/LOCAL/SRC
RUN yum-y Install libxml2 libxml2-devel bzip2 bzip2-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel FreeType Freetype-devel zlib zlib-devel Libcurl libcurl-devel
workdir/usr/local/src/php-5.6.30
RUN./configure--prefix=/usr/local/php--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd--with-mysql=mysqlnd-- With-openssl--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-mcrypt--with-zlib-- WITH-LIBXML-DIR=/USR--enable-xml--enable-sockets--enable-fpm--with-config-file-path=/usr/local/php/etc-- with-bz2--with-gd && make && make install
COPY Php.ini-production/usr/local/php/etc/php.ini
COPY php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
RUN useradd-m-s/sbin/nologin PHP
RUN sed-i-E ' [email protected];p id = run/[email protected] = Run/[email protected] '-e ' [Email protected]@[email Protect Ed] '-E ' [email protected] = 127.0.0.1:[email protected] = 0.0.0.0:[email protected] '/usr/local/php/etc/php-fpm.conf
RUN sed-i ' [email protected];d aemonize = [email protected] = [email protected] '/usr/local/php/etc/php-fpm.conf
EXPOSE 9000
CMD ["/USR/LOCAL/PHP/SBIN/PHP-FPM"]
Get the required files from GitHub, such as the following files in the final PHP folder above
[[email protected] php]# ls
Dockerfile init.d.php-fpm libmcrypt-2.5.7.tar.gz php-5.6.30.tar.bz2 php-fpm.conf.default php.ini-production
Building PHP images (lengthy process)
[[email protected] php]# Docker build-t PHP.
See if the build was successful
[email protected] php]# Docker Images | grep php
PHP latest 15fe39a66344 minutes ago 1.12 GB
Three: Start the container
Start PHP
[[email protected] php]# docker run-d--name=php-v/www:/usr/local/nginx/html php
Start Nginx
Docker run-d--name=nginx-p 80:80-v/www:/usr/local/nginx/html--link=php:php nginx
Check if the boot is normal, if the container is exited state, then use the Docker logs-f container name to see the error message
[email protected] php]# Docker ps-a
Create phpinfo and HTML files for testing under/WWW
[[email protected] www]# ls
Index.html test.php
Four: Access test
Linux under Dockerfile build Lnmp (currently only N and P)