系统相关
首页 > 系统相关> > centos下docker-compose搭建lnmp环境

centos下docker-compose搭建lnmp环境

作者:互联网

 

所有操作均在root权限下进行

sudo -i

 

1、新建文件夹【/root/lnmp】和文件【/root/lnmp/docker-compose.yml】

mkdir /root/lnmp
vi /root/lnmp/docker-compose.yml

 

2、写入yml文件内容

version: "3"  
services:   
  nginx:    
     image: nginx:latest
     container_name: c_nginx
     ports:
      - "80:80"
     #centos文件夹【/root/lnmp/nginx/html】和容器文件夹【/usr/share/nginx/html】进行绑定,并设rw权限
     #centos文件【/root/lnmp/nginx/conf/default.conf】和容器文件【/etc/nginx/conf.d/default.conf】进行绑定
     volumes:
      - /root/lnmp/nginx/html/:/usr/share/nginx/html/:rw
      - /root/lnmp/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
     #设置上海时区
     environment:
      TZ: "Asia/Shanghai"
     #容器自启
     restart: always
     #加入lnmp的网络
     networks:
      - lnmp
  php:
    image: php:7.3.29-fpm
    container_name: php_01
    volumes:
      - /root/lnmp/nginx/html/:/var/www/html/:rw
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - lnmp

  mysql:
    image: mysql:5.6
    container_name: mysql56
    ports:
      - "3306:3306"
    volumes:
      - /root/lnmp/mysql/data:/var/lib/mysql/:rw
    restart: always
    networks:
      - lnmp
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
      TZ: "Asia/Shanghai"
networks:   
  #新建自定义网络【lnmp】
  lnmp:

  

 

 

3、新建文件夹【/root/lnmp/nginx】、【/root/lnmp/nginx/conf】和文件【/root/lnmp/nginx/conf/default.conf】

mkdir /root/lnmp/nginx
mkdir /root/lnmp/nginx/conf
vi /root/lnmp/nginx/conf/default.conf

  

4、写入conf文件内容

server {
    listen       80;
    root   /usr/share/nginx/html;
    index   index.html index.php;


    # 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.php ;
        try_files $uri $uri/ /index.php?$query_string;
        autoindex  on;
    }


    location ~ \.php$ {
        #php_01是yml里的容器名
        fastcgi_pass   php_01:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
    }

}

  

5、进入lnmp文件夹启动yml文件

cd /root/lnmp
docker-compose up -d

  

 

标签:compose,centos,lnmp,nginx,html,conf,php,root
来源: https://www.cnblogs.com/zwgbk/p/16655361.html