Docker compose 编排LNP

Docker-compose 编排 LNP
目录结构
# 基础目录
/e/dq_lnp/
# 配置目录
- mysql
- nginx
    -- conf.d
        --- dq.conf            # 扩展配置
    -- logs
        --- access.log
        --- error.log
    Dockerfile                # dockerfile文件
    nginx.conf                # nginx配置文件
- php
    -- logs
    Dockerfile                # dockerfile文件
    php.ini                    # php配置文件
    www.conf                
- www                        # www目录
docker-compose.yml            # 编排文件
php的dockerfile
# 基础
FROM php:7.2-fpm
# 维护者
MAINTAINER dqdocker1@11.com
# 修改时区
ENV TZ Asia/Shanghai
RUN date -R

# 换源
RUN echo 'deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free' >/etc/apt/sources.list
RUN echo 'deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free' >>/etc/apt/sources.list
RUN apt-get update --fix-missing && apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev  \
        && docker-php-ext-configure gd --with-freetype-dir=/usr/include --with-jpeg-dir=/usr/include/jpeg \
        && docker-php-ext-install gd mysqli opcache pdo_mysql gd zip

ENV PHPREDIS_VERSION 5.0.1
ENV PHPXDEBUG_VERSION 2.6.0
ENV PHPSWOOLE_VERSION 4.5.10

RUN pecl install redis-$PHPREDIS_VERSION \
    && pecl install xdebug-$PHPXDEBUG_VERSION \
    && pecl install swoole-$PHPSWOOLE_VERSION \
    && docker-php-ext-enable redis xdebug swoole

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
     && php composer-setup.php \
     && php -r "unlink('composer-setup.php');" \
     && mv composer.phar /usr/local/bin/composer \
     && composer config -g repo.packagist composer https://packagist.phpcomposer.com
RUN apt-get install -y git

RUN rm -rf /var/cache/apt/* \
    && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/lib/sessions \
    && chmod o=rwx -R /var/lib/sessions
#容器启动时执行指令
CMD ["php-fpm"]
nginx的dockerfile
FROM nginx:1.15.5
MAINTAINER dqdocker1 mowang@qq.com
ENV TZ Asia/Shanghai
RUN date -R
CMD ["nginx", "-g", "daemon off;"]
docker-compose.yml 编排文件
version: '3'
services:
  php7.2:
    build:
      context: ./php
      dockerfile: Dockerfile
    container_name: php7.2
    volumes:
      - /e/docker/dq_lnp/php/php.ini:/usr/local/etc/php/php.ini
      - /e/docker/dq_lnp/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
      - /e/docker/dq_lnp/php/logs:/var/log/php
      - /e/docker/dq_lnp/www:/var/www/html
    ports:
      - 29000:9000
    depends_on:
      - nginx
    networks:
      - dq-lnp
  nginx:
    build:
      context: ./nginx
      dockerfile: Dockerfile
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - /e/docker/dq_lnp/www:/var/www/html
      - /e/docker/dq_lnp/nginx/logs:/var/log/nginx
      - /e/docker/dq_lnp/nginx/nginx.conf:/etc/nginx/nginx.conf
      - /e/docker/dq_lnp/nginx/conf.d:/etc/nginx/conf.d
    networks:
      - dq-lnp
networks:
  dq-lnp:
nginx配置文件
user  www-data;
worker_processes  1;

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;

}
nginx/conf.d/dq.conf
server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name mine.nginx.com;
    root        /var/www/html;
    index       index index.html index.php;

    location / {
        #-e表示只要filename存在,则为真
        if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
        }
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_pass   php7.2:9000;                                #php7.2 为php的容器名称
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }

    location ~* /\. {
        deny all;
    }
}
创建容器
docker-compose up -d
编排注意
  1. php.ini , www.conf 文件需要开启一个测试php容器中复制出来php.ini-development/php.ini-production,重命名php.ini即可

  2. 我这个是在windows的环境下,好像docker无法挂载文件,在第一次运行docker-compose up -d时无法挂载成功,需要删除之后重新挂载一次

  3. 注意需要在php.ini文件中开启对应的扩展

    extension=php_pdo_mysql.dll
    extension=php_pdo_oci.dll
    extension=php_pdo_odbc.dll
    extension=php_pdo_pgsql.dll
    extension=php_pdo_sqlite.dll
    extension=php_pgsql.dll
    extension=php_redis.dll
常用命令
# 创建镜像
docker-compose up -d
# 查看容器
docker ps -a
# 如果有容器未启动
docker start 容器名称
# 重启yml/关闭
docker-compose restart/stop
本作品采用《CC 协议》,转载必须注明作者和本文链接
别问我八十年代的哪首歌
qiuqiumade
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!