I. OS:
[Root@linuxea lnmp]# Cat/etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
Mariadb-10.0.27-linux
Nginx1.10:1
php5.6.26
II. Notice
Separating LNMP on Docker single machine
The/mydata/data Data directory has been placed on the host before Dockerfile, mounted/mydata/data to the container when run MySQL, and other log files and configuration files, which need to be specified in the configuration file DataDir directory
Iii. MySQL Dockerfile
[Root@linuxea mysql]# Cat Dockerfile
From CentOS
Maintainer Wwww.111cn.net and Mark make
RUN Yum makecache \
&& Yum install libaio-y \
&& curl-so http://mirrors.ds.com/tar%E5%8C%85/mariadb-10.0.27-linux-x86_64.tar.gz \
&& mv mariadb-10.0.27-linux-x86_64.tar.gz/usr/local \
&& Yum clean all \
&& tar xf/usr/local/mariadb-10.0.27-linux-x86_64.tar.gz-c/usr/local/\
&& rm-rf/usr/local/mariadb-10.0.27-linux-x86_64.tar.gz \
&& Groupadd-r-G 306 MySQL \
&& Useradd-r-G 306-u 306 mysql \
&& mkdir-p/mydata/data \
&& chown-r mysql.mysql/mydata \
&& chown-r root.mysql/usr/local/mariadb-10.0.27-linux-x86_64 \
&& ln-s/usr/local/mariadb-10.0.27-linux-x86_64/usr/local/mysql
Workdir/usr/local/mysql
RUN scripts/mysql_install_db--user=mysql--datadir=/mydata/data \
&& Rm-rf/mydata
ENV Path/usr/local/mysql/bin: $PATH
Expose 3306
EntryPoint Mysqld_safe
Iv. Nginx Dockerfile
The Nginx container is also mentioned in the previous chapters, dockerfile as follows:
Still configure, log files and Web site files are stored in the host and then mounted to the container
[Root@linuxea nginx]# Cat Dockerfile
From Marksugar/alpine
Maintainer Wwww.111cn.net
RUN addgroup-g 499-s nginx \
&& adduser-hdu 499-s/sbin/nologin-g ' Web server '-G nginx nginx \
&& cd/usr/local \
&& curl-so http://nginx.org/download/nginx-1.10.1.tar.gz \
&& Tar xf nginx-1.10.1.tar.gz \
&& RM-RF nginx-1.10.1.tar.gz \
&& apk--update--no-cache add GeoIP geoip-dev pcre libxslt gd openssl-dev \
Pcre-dev zlib-dev build-base linux-headers libxslt-dev gd-dev \
libstdc++ LIBGCC Patch logrotate Supervisor Inotify-tools
workdir/usr/local/nginx-1.10.1
RUN./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--HTTP-FASTCGI-TEMP-PATH=/VAR/TMP/NGINX/FASTCGI \
--HTTP-UWSGI-TEMP-PATH=/VAR/TMP/NGINX/UWSGI \
&& make && make install \
&& mkdir-p/var/tmp/nginx/{client,fastcgi,proxy,uwsgi} \
&& echo "daemon off;" >>/etc/nginx/nginx.conf \
&& apk del wget \
&& rm-rf/usr/local/nginx-1.10.1 \
&& rm-rf/var/cache/apk/* \
&& rm-rf/etc/nginx/nginx.conf
ENV Path/usr/local/nginx/sbin: $PATH
Expose 80
Entrypoint/usr/local/nginx/sbin/nginx
V. Nginx configuration file:
[Root@linuxea nginx]# Cat nginx.conf
User Nginx Nginx;
Error_log/data/nginx/wwwlog/error_nginx.log Crit;
Pid/var/run/nginx.pid;
Worker_rlimit_nofile 51200;
Events {
Use Epoll;
Worker_connections 51200;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;
Client_max_body_size 50m;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 120;
Server_tokens off;
Tcp_nodelay on;
# Fastcgi_connect_timeout 300;
# Fastcgi_send_timeout 300;
# Fastcgi_read_timeout 300;
# fastcgi_buffer_size 64k;
# fastcgi_buffers 4 64k;
# fastcgi_busy_buffers_size 128k;
# fastcgi_temp_file_write_size 128k;
# gzip on;
# gzip_buffers 8k;
# Gzip_comp_level 6;
# Gzip_http_version 1.1;
# gzip_min_length 256;
# gzip_proxied any;
# gzip_vary on;
# gzip_types
# text/xml application/xml application/atom+xml Application /rss+xml application/xhtml+xml image/svg+xml
# text/javascript application/javascript Application/x-javascript
# Text/x-json Application/json Application/x-web-app-manifest+json
# text/css text/plain text/x-component
# font/opentype application/ X-font-ttf application/vnd.ms-fontobject
# image/x-icon;
# gzip_disable "Msie6";
# Open_file_cache max=1000 inactive=20s;
# open_file_cache_valid 30s;
# open_file_cache_min_uses 2;
# open_file_cache_errors on;
# Log_format Access ' $remote _addr-$remote _user [$time _local] ' $request '
# ' $status $body _bytes_sent ' $http _referer '
# ' $http _user_agent ' $http _x_forwarded_for ';
# Log_format upstream2 ' $proxy _add_x_forwarded_for $remote _user [$time _local] ' $request ' $http _host '
# ' $body _bytes_sent ' $http _referer ' $http _user_agent ' $ssl _protocol $ssl _cipher '
# ' $request _time [$status] [$upstream _status] [$upstream _response_time] "$upstream _addr";
###########################################################################################
server {
Listen 80;
server_name localhost;
Location/{
Root/data/nginx/wwwroot;
Index index.php index.html index.htm;
}
# location/nginx_status {
# stub_status on;
# Access_log off;
# Allow 127.0.0.1;
# #deny All;
# }
Location ~ \.php$ {
Root/data/nginx/wwwroot;
Fastcgi_pass phpfpm:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/data/nginx/wwwroot$fastcgi_script_name;
Include fastcgi.conf;
}
Access_log/data/nginx/wwwlog/www.com.log;
}
Include vhost/*.conf;
}
Daemon off;
[Root@linuxea nginx]#
VI. PHP-FPM Dockerfile
[Root@linuxea php-fpm]# Cat Dockerfile
From CentOS
Maintainer Wwww.111cn.net for Mark
RUN curl-so http://ftp.ntu.edu.tw/php/distributions/php-5.5.26.tar.gz \
&& tar xf php-5.5.26.tar.gz-c/usr/local/\
&& mv/usr/local/php-5.5.26/usr/local/php \
&& RM-RF php-5.5.26.tar.gz
workdir/usr/local/php
RUN groupadd-g 499-r nginx \
&& useradd-u 499-g nginx-r nginx-s/sbin/nologin
&& Yum install epel*-y \
&& Yum install-y gcc automake autoconf libtool make \
Libxml2-devel \
OpenSSL \
Openssl-devel \
BZIP2 \
Bzip2-devel \
libpng \
Libpng-devel \
FreeType \
Freetype-devel \
Libcurl-devel \
Libcurl libjpeg \
Libjpeg-devel \
libpng \
Libpng-devel \
FreeType \
Freetype-devel \
Libmcrypt-devel \
Libmcrypt \
Libtool-ltdl-devel \
Libxslt-devel \
Mhash \
Mhash-devel \
&&/configure--prefix=/usr/local/php \
--DISABLE-PDO \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--enable-sockets \
--enable-sysvsem \
--ENABLE-SYSVSHM \
--ENABLE-PCNTL \
--enable-mbregex \
--enable-xml \
--enable-zip \
--ENABLE-FPM \
--enable-mbstring \
--with-pcre-regex \
--with-mysql \
--WITH-MYSQLI \
--WITH-GD \
--with-jpeg-dir \
--WITH-BZ2 \
--with-zlib \
--with-mhash \
--with-curl \
--with-mcrypt \
--with-jpeg-dir \
--with-png-dir \
&& make \
&& make install \
&& Yum Remove make-y\
&& Yum Clean All
#ENV Path/usr/local/php/sbin: $PATH
#EXPOSE 9000
ENTRYPOINT/USR/LOCAL/PHP/SBIN/PHP-FPM--nodaemonize
Vii. php-fpm.conf
[Root@linuxea php-fpm]# Cat php-fpm.conf
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
; Global Options;
;;;;;;;;;;;;;;;;;;
[Global]
PID = Run/php-fpm.pid
Error_log = Log/php-fpm.log
Log_level = Warning
Emergency_restart_threshold = 30
Emergency_restart_interval = 60s
Process_control_timeout = 5s
Daemonize = No
;;;;;;;;;;;;;;;;;;;;
; Pool definitions;
;;;;;;;;;;;;;;;;;;;;
[PHP]
; listen =/dev/shm/php-cgi.sock
Listen = 9000
Listen.backlog =-1
; listen.allowed_clients = 127.0.0.1
Listen.owner = Nginx
Listen.group = Nginx
Listen.mode = 0777
user = Nginx
Group = Nginx
; Come from Www.111cn.net for Mark
PM = dynamic
Pm.max_children = 12
Pm.start_servers = 8
Pm.min_spare_servers = 6
Pm.max_spare_servers = 12
Pm.max_requests = 2048
Pm.process_idle_timeout = 10s
Request_terminate_timeout = 120
Request_slowlog_timeout = 0
Pm.status_path =/php-fpm_status
Slowlog = Log/slow.log
Rlimit_files = 51200
Rlimit_core = 0
Catch_workers_output = yes
; Env[hostname] = $HOSTNAME
Env[path] =/usr/local/bin:/usr/bin:/bin
ENV[TMP] =/tmp
ENV[TMPDIR] =/tmp
ENV[TEMP] =/tmp
[Root@linuxea php-fpm]#
We are in run PHP is need to put the Nginx website root directory also mount in
Copyright belongs to: www.111cn.net
The source and this statement shall be specified when reproduced
VIII. directory structure:
[Root@linuxea lnmp]# tree-l 4
.
├──docker-compose.yml
├──log
│├──nginx
││├──wwwlog
││└──wwwroot
││└──index.php
│├──php-fpm.log
│├──php-fpm.log.slow
│└──www.111cn.net
├──mysql
│├──dockerfile
│├──mariadb-10.0.27-linux-x86_64.tar.gz
│├──my.cnf
│└──mydata
│├──data
││├──1033805cad2d.pid
││├──1639a5882354.pid
││├──2619917b9ae6.pid
││├──5c05812ed420.pid
││├──909d6ef97f04.pid
││├──aria_log.00000001
││├──aria_log_control
││├──b83f3b6a702f.pid
││├──dff35cf18443.pid
││├──ibdata1
││├──ib_logfile0
││├──ib_logfile1
││├──linuxea
││├──multi-master.info
││├──mysql
││├──mysql-bin.000001
││├──mysql-bin.000002
││├──mysql-bin.000003
││├──mysql-bin.000004
││├──mysql-bin.000005
││├──mysql-bin.000006
││├──mysql-bin.000007
││├──mysql-bin.000008
││├──mysql-bin.000009
││├──mysql-bin.000010
││├──mysql-bin.index
││├──performance_schema
││└──test
│└──log
│└──mysql-error.log
├──nginx
│├──dockerfile
│├──log
││├──error_nginx.log
││└──www.com.log
│├──nginx.conf
│├──www.conf
│└──wwwroot
│├──helo.php
│├──index.html
│├──index.php
│└──mysql.php
└──php-fpm
├──dockerfile
├──log
├──php-fpm.conf
├──php-fpm.conf.bak
├──php-fpm.conf.default
└──php.ini
directories, files
[Root@linuxea lnmp]#
Mount the appropriate configuration file and data directory
Ix. MARIADB Launch
Boot order Mysql->php->nginx
[Root@linuxea Lnmp] Docker run--name mysql1 \
-V/ROOT/LNMP/MYSQL/MY.CNF:/ETC/MYSQL/MY.CNF \
-v/root/lnmp/mysql/mydata/data:/mydata/data \
-v/root/lnmp/mysql/mydata/log:/mydata/log \
-E mysql_root_password=linuxea \
-d-p 3306:3306 mariadb:10.0.27
X. PHP-FPM Startup
[Root@linuxea Lnmp] Docker run--name phpfpm \
--link MYSQL1:MYSQL1 \
-V/ROOT/LNMP/PHP-FPM/PHP-FPM.CONF:/USR/LOCAL/PHP/ETC/PHP-FPM.CONF:RW \
-v/root/lnmp/log:/data-v/root/lnmp/nginx/wwwroot:/data/nginx/wwwroot \
-D php-fpm:5.6.24
If php.ini need to be mounted, position:/usr/local/php/lib
XI. Nginx Launch
[Root@linuxea Lnmp] Docker run--name nginx \
--link phpfpm:phpfpm \
-v/root/lnmp/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v/root/lnmp/nginx/log:/data/nginx/wwwlog \
-v/root/lnmp/nginx/wwwroot:/data/nginx/wwwroot \
--volumes-from phpfpm \
-d-p 80:80 nginx1.10:1
XII View startup status
[Root@linuxea lnmp]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2d2a8e11454 nginx1.10:1 "/bin/sh-c/usr/loca" hours ago up 2 seconds 0.0.0.0:80->80 /tcp Nginx
c89e724b0973 php-fpm:2 "/bin/sh-c '/usr/loc" hours ago up 3 seconds phpfpm
1639a5882354 mariadb:10.0.27 "/bin/sh-c Mysqld_sa" hours ago up seconds 0.0.0.0:3306-> 3306/tcp MYSQL1
[Root@linuxea lnmp]#
XIII Verification Phpinfo
[Root@linuxea wwwroot]# Cat index.php
<?php
Phpinfo ();
?>
[Root@linuxea wwwroot]#
XIV. Verify MySQL Link
Authorize an account
[root@1639a5882354/]#/usr/local/mysql/bin/mysql-uroot-p-h127.0.0.1
Enter Password:
Welcome to the MARIADB Monitor. Commands End With; or \g.
Your mariadb Connection ID is 8
Server VERSION:10.0.27-MARIADB MARIADB Server
Copyright (c), 2016, Oracle, mariadb Corporation Ab and others.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
MARIADB [(None)]> CREATE DATABASE linuxea CHARACTER SET UTF8;
Query OK, 1 row Affected (0.00 sec)
MARIADB [(None)]> GRANT all in linuxea.* to ' linuxea ' @ '% ' identified by ' Linuxea ';
Query OK, 0 rows Affected (0.00 sec)
Create a MySQL link php file
[Root@linuxea wwwroot]# Cat mysql.php
<?php
$link =mysql_connect ("Mysql1", "Linuxea", "Linuxea");
if (! $link) echo "<center>else echo "<center><br/>?>
[Root@linuxea wwwroot]# Curl 10.10.239.194/mysql.php
<center><br/>[Root@linuxea wwwroot]#
XV Install WordPress
Here the IP may need to be manually specified, if trouble can directly use the Hosts network mode
XVI. Docker-compost
[Root@linuxea ~]# Cat Lnmp/docker-compose.yml
Version: ' 2 '
Services
Mysql:
Container_name:mysql-1
image:mariadb:10.0.27
Ports
-"3,306:3,306"
Environment:
-Mysql_root_password=linuxea
Volumes:
-/ROOT/LNMP/MYSQL/MY.CNF:/ETC/MYSQL/MY.CNF
-/root/lnmp/mysql/mydata/data:/mydata/data
-/root/lnmp/mysql/mydata/log:/mydata/log
PHPFPM:
Container_name:phpfpm-1
Image:php-fpm:2
Ports
-"9,000:9,000"
Links
-"Mysql:mysql"
Volumes:
-/root/lnmp/php-fpm/php-fpm.conf:/usr/local/php/etc/php-fpm.conf
-/root/lnmp/log:/data/phplog
-/root/lnmp/nginx/wwwroot:/data/nginx/wwwroot
Nginx:
Container_name:nginx-1
Image:nginx1.10:1
Ports
-"80:80"
Links
-"phpfpm:php"
Volumes_from:
-"PHPFPM"
Volumes:
-/root/lnmp/nginx/nginx.conf:/etc/nginx/nginx.conf
-/root/lnmp/nginx/log:/data/nginx/wwwlog
-/root/lnmp/nginx/wwwroot:/data/nginx/wwwroot
[Root@linuxea ~]#