目錄結構:
/usr/local/lnmp 下存放 :
1,docker-compose.yml 檔案
2,memcached 目錄
3,mysql :data 目錄, dockerfile 檔案
4,php : dockerfile檔案
5,nginx : dockerfile 檔案 ,conf 目錄 :default.conf檔案 ,html目錄
一,mysql的dockerfile構建
from mysql:8.0
# 設定時區
env tz=asia/shanghai
run ln -snf /usr/share/zoneinfo/$tz /etc/localtime && echo $tz > /etc/timezone
設定時區即可,
二,php的dockerfile構建
安裝php7.2提示libzip版本低於1.2.0,暫時沒有解決。所以用了php7.1 ,各項引數參閱docker官方即可。from php:7.1-fpm
# 設定時區
env tz=asia/shanghai
run ln -snf /usr/share/zoneinfo/$tz /etc/localtime && echo $tz > /etc/timezone
# 安裝 php 拓展
run apt-get update && apt-get install -y \
apt-utils \
libmemcached-dev \
libsasl2-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
libbz2-dev \
libmcrypt-dev \
libxml2-dev \
libcurl3-dev \
pkg-config \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install opcache \
&& docker-php-ext-install mysqli \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install memcached-3.0.4 \
&& docker-php-ext-enable memcached
# 建立使用者
run usermod -u 1000 www-data
三,nginx的dockerfile
from nginx:latest
# 設定時區
env tz=asia/shanghai
run ln -snf /usr/share/zoneinfo/$tz /etc/localtime && echo $tz > /etc/timezone
同mysql設定時區即可。
php下conf目錄中default.conf的內容:
四,memcaced的dockerfileserver
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#error_page 500 502 503 504 /50x.html;
location = /50x.html
# proxy the php scripts to apache listening on 127.0.0.1:80
##location ~ \.php$
# pass the php scripts to fastcgi server listening on 127.0.0.1:9000
#location ~ \.php$
# deny access to .htaccess files, if apache's document root
# concurs with nginx's one
##location ~ /\.ht
from memcached
更加簡單,來自官方映象即可。
五,docker-compose.yml的配置
version: '2'
services:
mysql:
build:
context: ./mysql
ports:
- "3306:3306"
volumes:
- ./mysql/data:/var/lib/mysql
environment:
mysql_root_password: 123456
mysql_database: test
mysql_user: weiwei
mysql_password: zjw1989a
restart: on-failure
networks:
- backend
container_name: mysql
nginx:
build:
context: ./nginx
depends_on:
- php
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/html:/html
- ./nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
restart: on-failure
command: nginx -g 'daemon off;'
networks:
- frontend
container_name: nginx
php:
build:
context: ./php
ports:
- "9000:9000"
depends_on:
- mysql
- memcached
links:
- mysql:mysql
- memcached:memcached
volumes:
- ./nginx/html:/html
networks:
- frontend
- backend
restart: on-failure
container_name: php
memcached:
build:
context: ./memcached
ports:
- "11211:11211"
restart: on-failure
container_name: memcached
networks:
- frontend
networks:
frontend:
backend:
構建LNMP平台
2.構建lnmp平台 問題沿用練習一,通過調整nginx服務端配置,實現以下目標 1 配置fast cgi支援php網頁 2 建立php測試頁面,測試使用php連線資料庫的效果 方案使用2臺rhel6虛擬機器,其中一台作為lnmp伺服器 192.168.4.5 另外一台作為測試用的linux客戶機 ...
構建LNMP平台1
實現此案例需要按照如下步驟進行。步驟一 php fpm配置檔案 1 檢視php fpm配置檔案 實驗中不需要修改該檔案 root proxy etc vim etc php fpm.d www.conf www listen 127.0.0.1 9000 php埠號 pm.max children ...
構建LNMP平台2
實現此案例需要按照如下步驟進行。步驟一 php fpm配置檔案 1 檢視php fpm配置檔案 實驗中不需要修改該檔案 root proxy etc vim etc php fpm.d www.conf www listen 127.0.0.1 9000 php埠號 pm.max children ...