Dockre构建自用Lnmp

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/youcijibi/article/details/88855552

目录结构:

/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构建

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

安装php7.2提示libzip版本低于1.2.0,暂时没有解决。所以用了php7.1 ,各项参数参阅docker官方即可。

三,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的内容:
 

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /html;
        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   php:9000; #docker容器的名字(php)
        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;
    #}

四,memcaced的Dockerfile

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:

有问题欢迎留言讨论。

猜你喜欢

转载自blog.csdn.net/youcijibi/article/details/88855552
今日推荐