Docker之使用Docker-compose搭建LNMP环境

匿名 (未验证) 提交于 2019-12-03 00:09:02

  之前有随笔介绍使用Docker-compose搭建LNMP环境(centos6 php5.6)

  本文介绍Docker-compose搭建LNMP环境(centos7 php7)

  文件目录结构如下

 

wget http://nginx.org/download/nginx-1.16.1.tar.gz wget https://libzip.org/download/libzip-1.2.0.tar.gz wget https://www.php.net/distributions/php-7.3.9.tar.gz 

version: '3' services:   nginx:     hostname: nginx     build:       context: ./nginx       dockerfile: Dockerfile     ports:       - "80:80"     links:       - php:php-cgi     volumes:       - ./wwwroot:/usr/local/nginx/html    php:     hostname: php     build: ./php     links:       - mysql:mysql-db     volumes:       - ./wwwroot:/usr/local/nginx/html    mysql:     hostname: mysql     image: mysql:5.7     ports:       - "3306:3306"     volumes:       - ./mysql/conf:/etc/mysql/conf.d       - ./mysql/data:/var/lib/mysql     environment:       MYSQL_ROOT_PASSWORD: 123456       MYSQL_DATABASE: wordpress       MYSQL_USER: user       MYSQL_PASSWORD: user123 

[mysqld] user=mysql port=3306 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock pid-file=/var/run/mysqld/mysql.pid log_error=/var/log/mysql/error.log character_set_server = utf8 max_connections=3600 

[mysqld] user=mysql port=3306 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock pid-file=/var/run/mysqld/mysql.pid log_error=/var/log/mysql/error.log character_set_server = utf8 max_connections=3600 root@test-docker1:/data/compose_lnmp# cat nginx/Dockerfile  FROM centos:7 MAINTAINER liuym RUN yum install -y gcc-c++ zlib-devel pcre-devel make ADD nginx-1.16.0.tar.gz /tmp RUN cd /tmp/nginx-1.16.0 && ./configure --prefix=/usr/local/nginx && make -j 2 && make install RUN rm -f /usr/local/nginx/conf/nginx.conf COPY nginx.conf /usr/local/nginx/conf  EXPOSE 80 CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"] 

user  root; worker_processes  auto;   error_log  logs/error.log  info;   pid        logs/nginx.pid;     events {     use epoll; }   http {       include       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 logs/access.log main;     sendfile        on;     keepalive_timeout  65;       server {         listen 80;         server_name localhost;         root html;         index index.html index.php;           location ~ \.php$ {             root html;             fastcgi_pass php-cgi:9000;             fastcgi_index  index.php;             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;             include fastcgi_params;         }     } } 

FROM centos:7 MAINTAINER liuym RUN yum install -y gcc gcc-c++ gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel make perl ADD libzip-1.2.0.tar.gz /tmp RUN cd /tmp/libzip-1.2.0 && \     ./configure && \     make && \     make install ADD php-7.3.9.tar.gz /tmp RUN cd /tmp/php-7.3.9 && \     ./configure --prefix=/usr/local/php \     --with-config-file-path=/usr/local/php/etc \     --with-mysql --with-mysqli \     --with-openssl --with-zlib --with-curl --with-gd \     --with-jpeg-dir --with-png-dir --with-iconv \     --enable-fpm --enable-zip --enable-mbstring && \     cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/ && \     make -j 4 && make install && \     cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \     cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf  && \     sed -i "s/127.0.0.1/0.0.0.0/g" /usr/local/php/etc/php-fpm.d/www.conf && \     cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && \     chmod +x /etc/init.d/php-fpm #COPY php.ini /usr/local/php/etc  EXPOSE 9000 CMD /etc/init.d/php-fpm start  && tail -F /var/log/messages 

  wwwroot/test.php

<?php phpinfo()?> 

docker-compose up -d 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!