docker 搭建lnmp環(huán)境的方法步驟
創(chuàng)建項(xiàng)目目錄
mkdir php
創(chuàng)建如下項(xiàng)目結(jié)構(gòu)
- sites 目錄放置項(xiàng)目文件
- services 目錄放置服務(wù)相關(guān)配置
- script 放置自定義腳本
├── Readme.md ├── docker-compose.yml ├── script ├── services │ ├── mariadb │ │ └── Dockerfile │ ├── nginx │ │ ├── Dockerfile │ │ ├── conf.d │ │ │ └── default.conf │ │ └── nginx.conf │ ├── php │ │ └── Dockerfile │ └── redis │ └── Dockerfile └── sites ├── index.html └── index.php 8 directories, 10 files
編輯docker-compose文件
version: "3" services: php: build: ./services/php # ports: # - "9001:9000" container_name: lnmp-php restart: always volumes: - ./sites:/www networks: lnmp_net: ipv4_address: 101.11.11.10 nginx: build: ./services/nginx ports: - "81:80" - "444:443" container_name: lnmp-nginx restart: always volumes: - ./sites:/www - ./services/nginx/nginx.conf:/etc/nginx/nginx.conf - ./services/nginx/conf.d:/etc/nginx/conf.d:rw networks: lnmp_net: ipv4_address: 101.11.11.11 networks: lnmp_net: driver: bridge ipam: config: - subnet: 101.11.11.0/20
編輯services/nginx文件
FROM nginx:1.17.0-alpine # 更新安裝源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 設(shè)置時(shí)區(qū)為上海 RUN apk update && apk add --upgrade \ && apk add tzdata \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone \ && apk del tzdata
編輯services/php文件
FROM php:7.3.6-fpm-alpine3.9 # 更新安裝源 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 設(shè)置時(shí)區(qū)為上海 RUN apk update && apk add --no-cache tzdata autoconf gcc g++ make zlib-dev curl-dev\ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone \ && apk del tzdata \ && docker-php-ext-install mysqli pdo_mysql opcache \ && pecl install grpc protobuf xdebug yaf yar swoole \ && docker-php-ext-enable xdebug yaf yar swoole grpc protobuf
以上我們的lnmp環(huán)境基本搭建完畢,下面我們針對(duì)Php解析做相關(guān)的配置
修改services/nginx/nginx.conf,可根據(jù)需求自行修改
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
修改services/nginx/conf.d目錄下文件
該目錄是各個(gè)項(xiàng)目的配置文件,可根據(jù)需求配置單個(gè)或多個(gè)服務(wù)
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
#root /usr/share/nginx/html;
root /www;
index index.php index.html index.htm;
#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 {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 101.11.11.10:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
啟動(dòng)服務(wù)
cd php && docker-compose up --build -d
上述的步驟根據(jù)網(wǎng)速的docker的配置執(zhí)行時(shí)間個(gè)不相同,因?yàn)閜hp中編譯了些許擴(kuò)展,也可根據(jù)自身需求做響應(yīng)的刪減
通過瀏覽器訪問http://127.0.0.1:81,如果看到了phpinfo的輸出信息,那么恭喜你,你的lnmp環(huán)境已經(jīng)部署完成
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Dockerfile中yum install無法使用的問題及解決
在使用Dockerfile自定義CentOS 7容器過程中,可能會(huì)遇到容器內(nèi)無法使用yum命令的問題,首先,確認(rèn)主機(jī)是否能聯(lián)網(wǎng),其次,檢查在Dockerfile打包新容器時(shí),容器是否能聯(lián)網(wǎng),若發(fā)現(xiàn)容器無法聯(lián)網(wǎng),一種解決方法是編輯/etc/docker/daemon.json文件2024-11-11
Docker安裝ELK并實(shí)現(xiàn)JSON格式日志分析的方法
這篇文章主要介紹了Docker安裝ELK并實(shí)現(xiàn)JSON格式日志分析的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Docker 給運(yùn)行中的容器設(shè)置端口映射的方法
這篇文章主要介紹了Docker 給運(yùn)行中的容器設(shè)置端口映射的方法,詳細(xì)的介紹了端口映射的概念和方法,具體一定的參考價(jià)值,有興趣的可以了解一下2017-11-11
CentOS7 Docker防火墻的簡(jiǎn)單配置教程
這篇文章主要給大家介紹了關(guān)于CentOS7 Docker防火墻的簡(jiǎn)單配置方法,以及總結(jié)了docker在centos7下的一些坑,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12

