docker-compose搭建lnmp运营环境

文件路径

.
├── Dockerfile 
├── conf 
│   ├── default.conf 
│   ├── php-fpm.conf
│   ├── php.ini
│   └── redis.conf
├── docker-compose.yml
├── mysql
│   └── data
└── www
    └── DoorVietnam //项目

docker-compose.yml

version: "3"
services:
  nginx:
    image: nginx:1.15.7-alpine
    container_name: nginx15
    ports:
      - "5000:80"
    volumes:
      - ./www/:/var/www/html/:rw
      - ./conf/default.conf:/etc/nginx/conf.d/default.conf
    environment:
      TZ: "Asia/Shanghai"
    restart: always
    networks:
      - default

  php:
    build: .
    container_name: php72
    volumes:
      - ./www/:/var/www/html/:rw
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - default

  mysql:
    image: mysql:5.7
    container_name: mysql57
    ports:
      - "3307:3306"
    volumes:
      - ./mysql/data:/var/lib/mysql/:rw
    restart: always
    networks:
      - default
    environment:
      MYSQL_ROOT_PASSWORD: "11111111"
      TZ: "Asia/Shanghai"

  redis:
    image: redis:5.0.3
    container_name: redis50
    ports:
      - "6379:6379"
    volumes:
      - ./conf/redis.conf:/usr/local/etc/redis/redis.conf:ro
    restart: always
    entrypoint: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    environment:
      TZ: "Asia/Shanghai"
    networks:
      - default

networks:
  default:

Dockerfile

FROM php:7.2-fpm as php72
RUN RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \ vim
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \

default.conf

server {
    listen       80;
    server_name  localhost;
    root   /var/www/html/DoorVietnam/public;
    index  index.php index.html index.htm;
    #charset koi8-r;
    
    #access_log /dev/null;
    access_log  /var/www/html/DoorVietnam/storage/nginx.DoorVietnam.access.log  main;
    error_log  /var/www/html/DoorVietnam/storage/nginx.DoorVietnam.error.log  warn;
    
    #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;
    }

    location / {
        index  index.html index.htm index.php l.php;
        try_files $uri $uri/ /index.php?$query_string;
        autoindex  on;
    }

    # 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$ {
        fastcgi_pass   lnmp_php72_1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

推荐阅读更多精彩内容