A few simple steps will teach you how to use dockerfile to make an LNMP image, so don’t learn it quickly

A few simple steps will teach you how to use dockerfile to make LNMP images

Preface

Insert picture description here

Note: When engaging in a docker environment, remember to turn off firewalld and selinux, otherwise many docker services will not start

One, dockerfile compose php image

FROM centos:7.4.1708
ENV TIME_ZOME Asia/Shanghai
ARG WJ="php-7.1.10"
ADD $WJ.tar.bz2 /opt
RUN yum -y install gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel bison \
    && mkdir -p /usr/local/php/etc \
    && cd /opt/$WJ \
    && ./configure --prefix=/usr/local/php \
        --with-config-file-path=/usr/local/php/etc \
        --with-gd --with-mysqli \
        --with-openssl --with-zlib --with-curl \
        --with-jpeg-dir --with-png-dir --with-iconv \
        --enable-fpm --enable-zip --enable-mbstring \
    && make -j 2 \
    && make install \
    && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf \
    && cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf \
    && sed -i '/;daemonize/a\daemonize = no' /usr/local/php/etc/php-fpm.conf \
    && sed -i 's/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.d/www.conf \
    && echo "${TIME_ZOME}" > /etc/timezone \
    && ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime \
    && rm -rf /opt/local/php* \
    && yum clean all \
    && yum -y remove gcc gcc-c++ make \
    && mkdir -p /usr/local/nginx/html \
    && echo -e "<?php\nphpinfo();\n?>" > /usr/local/nginx/html/index.php

WORKDIR /usr/local/php/
EXPOSE 9000
CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"]

File structure:

Insert picture description here

Create a php mirror:

Insert picture description here

Two, dockerfile compose mysql image

FROM centos:7.4.1708
ADD mysql-5.6.26.tar.gz /opt
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \
    &&  useradd -s /sbin/nologin mysql \
    && yum -y install gcc gcc-c++ make pcre-devel expat-devel perl ncurses-devel autoconf cmake \
    && cd /opt/mysql-5.6.26/ \
    && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DSYSCONFIDIR=/etc -DMYSQL_DATADIR=/home/mysql/ -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
    && make -j2 \
    && make install \
    && cp -f support-files/my-default.cnf /etc/my.cnf \
    && cp support-files/mysql.server /etc/init.d/mysqld \
    && chown -R mysql:mysql /usr/local/mysql/ \
    && sed -i 's/^basedir/basedir=\/usr\/local\/mysql/g' /etc/init.d/mysqld \
    && sed -i 's/^datadir/datadir=\/home\/mysql/g' /etc/init.d/mysqld \
    && /usr/local/mysql/scripts/mysql_install_db --user=mysql --ldata=/var/lib/mysql --basedir=/usr/local/mysql --datadir=/home/mysql
ENV PATH /usr/local/mysql/bin:$PATH
EXPOSE 3306
ENTRYPOINT ["/usr/local/mysql/bin/mysqld_safe"]

File structure:

Insert picture description here

Create a mysql mirror:

Insert picture description here

Three, dockerfile compose nginx image

FROM centos:7.4.1708
ADD nginx-1.12.0.tar.gz /opt
RUN yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make \
    && useradd -M -s /sbin/nologin nginx \
    && cd /opt/nginx-1.12.0/ \
    && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-file-aio --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module \
    && make \
    && make install \
    && ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
    && echo -e "events {\nuse epoll;\nworker_connections  1024;\n}\nhttp {\nserver_tokens on;\nserver {\nlisten       80;\nserver_name  localhost;\nlocation / {\nroot   html;\nindex  index.html index.htmi index.php;\n}\nerror_page   500 502 503 504  /50x.html;\nlocation = /50x.html {\nroot   html;\n}\nlocation ~ \.php$ {\nroot           html;\nfastcgi_pass   172.168.184.30:9000;\nfastcgi_index  index.php;\nfastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;\ninclude        fastcgi_params;\n}\n}\n}" > /usr/local/nginx/conf/nginx.conf 
ENV PATH /usr/local/nginx/sbin:$PATH
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

File structure:

Insert picture description here

Create a mysql mirror:

Insert picture description here

Fourth, check the mirroring situation

Insert picture description here

Five, open nginx, mysql and php mirroring separately

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Six, test

Insert picture description here