Docker-compose部署nginx

Docker-compose部署nginx

目录结构

.
| -- conf.d
|    | -- nginx.conf
| -- dist
|    | -- index.html
|    | -- 50x.html
| -- compose-nginx.yaml
| -- startup.sh

compose-nginx.yaml

version: '3'

# docker network create nginx_bridge
networks:
  nginx_bridge:
    driver: bridge

services:
  nginx:
    image: nginx:stable-alpine
    #image: nginx:1.19.1-alpine
    container_name: nginx-alpine
    restart: always
    privileged: true
    environment:
      - TZ=Asia/Shanghai 
    ports:
      - 8080:80
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      #- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./conf.d:/etc/nginx/conf.d
      - ./log:/var/log/nginx
      - ./dist:/opt/dist:ro
    networks:
      - nginx_bridge

nginx.conf

这里只需要包含server配置,这个配置会内包含在容器内的nginx.conf(主配置中)


server {
        listen       80;
        server_name  192.168.31.202;
        client_max_body_size    1000M;
        #root         /opt/dist;

        #client_max_body_size 20M;

        # Load configuration files for the default server block.

        location / {
              root /opt/dist;
              index index.html;
        }

}

startup.sh

#! /usr/bin/bash
# 定义一个名称变量
network_name="nginx_bridge"

filterName=`docker network ls | grep $network_name | awk '{ print $2 }'`

if [ "$filterName" == "" ]; then
    # 不存在就创建
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-nginx.yaml up -d
docker ps -a
docker logs -f nginx-alpine

posted @ 2020-07-14 19:07  itwetouch  阅读(10272)  评论(0编辑  收藏  举报