docker部署项目

  1. nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            # 前端项目的文件路径
            root   /etc/nginx/docs/html;
            index  index.html index.htm;
            # 没有下面这行代码的话,请求会报 404
            try_files $uri $uri/ /index.html;
            # 解决 nginx 静态资源访问不支持 post 请求
            error_page 405 =200 @405;
        }

        # 解决 nginx 静态资源访问不支持 post 请求
        location @405 {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # ip 为后端服务地址
            proxy_pass http://soil-backend:8080$request_uri;
        }

        # 用于发送获取验证码之类的请求(可能是不走 axios 的请求)
        location /api {
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://soil-backend:8080;
        }

        # 避免 actuator 暴露
        if ($request_uri ~ "/actuator") {
            return 403;
        }

        #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   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   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

compose.yaml

# 指定撰写格式。 支持的版本有:2.x、3.x
version: "3.9"

# 允许服务相互通信的层。
networks:
  # 自定义的网络名称
  soil:
    # 指定该网络应使用哪个驱动程序。
    driver: bridge

# 服务是应用程序中计算资源的抽象定义,可以独立于其他组件进行扩展/替换。
services:
  soil-redis:
    # 覆盖容器映像声明的默认命令(即通过 Dockerfile 的 CMD)。
    command: >
      bash -c '
        chmod +x /usr/local/bin/healthcheck.sh;
        redis-server /etc/redis/redis.conf;
      '
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-redis
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "/usr/local/bin/healthcheck.sh" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-redis
    # 指定启动容器的图像。
    image: redis:7.2.4
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "6379:6379"
    # 定义平台在容器终止时应用的策略。
    restart: always
    # 定义服务容器必须可以访问的挂载主机路径或命名卷。
    volumes:
      - ./docker/redis/conf/redis.conf:/etc/redis/redis.conf
      - ./docker/redis/data:/data
      - ./docker/redis/sh/healthcheck.sh:/usr/local/bin/healthcheck.sh
  soil-elasticsearch:
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-elasticsearch
    # 定义容器中设置的环境变量。
    environment:
      ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
      ES_JAVA_OPTS: -Xms512m -Xmx512m
      DISCOVERY: single-node
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "curl -k -u elastic:${ELASTIC_PASSWORD} https://localhost:9200/_cat/health?h=status | grep -q '[(green)(yellow)]'" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-elasticsearch
    # 指定启动容器的图像。
    image: elasticsearch:${STACK_VERSION}
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "9200:9200"
      - "9300:9300"
    # 定义平台在容器终止时应用的策略。
    restart: always
  soil-kibana:
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-kibana
    # 表示服务之间的启动和关闭依赖关系。
    depends_on:
      soil-elasticsearch:
        condition: service_healthy
    # 定义容器中设置的环境变量。
    environment:
      # - i18n.locale=zh-CN 没有效果,并且字母必须大写,. 用 _ 代替
      I18N_LOCALE: zh-CN
      # 最终用户访问 Kibana 的公开可用 URL。
      # http必须包括协议、主机名、端口(如果与和 的默认值不同https,分别为 80 和 443)以及 server.basePath(如果已配置)。
      # 此设置不能以斜杠 (/) 结尾。
      SERVER_PUBLICBASEURL: http://soil-kibana:5601
      XPACK_REPORTING_ROLES_ENABLED: false
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "curl -s -I http://localhost:5601/api | grep -q 'HTTP/1.1 200 OK'" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-kibana
    # 指定启动容器的图像。
    image: kibana:${STACK_VERSION}
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "5601:5601"
    # 定义平台在容器终止时应用的策略。
    restart: always
  soil-logstash:
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-logstash
    # 表示服务之间的启动和关闭依赖关系。
    depends_on:
      soil-elasticsearch:
        condition: service_healthy
    # 定义容器中设置的环境变量。(源于日志提示)
    environment:
      XPACK_MONITORING_ENABLED: true
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "curl -f http://localhost:9600/_node | grep -q '\"status\":\"green\"'" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-logstash
    # 指定启动容器的图像。
    image: logstash:${STACK_VERSION}
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "5044:5044"
      - "9600:9600"
    # 定义平台在容器终止时应用的策略。
    restart: always
    # 定义服务容器必须可以访问的挂载主机路径或命名卷。
    volumes:
      - /docker/elastic/logstash/logs:/usr/share/logstash/logs
  soil-backend:
    # 指定用于从源创建容器映像的构建配置。
    build:
      # 包含 Dockerfile 的目录的路径,或 git 存储库的 url。
      context: ./docker/soil-backend
      # Compose 使用备用文件进行构建。 还必须指定构建路径。
      dockerfile: Dockerfile
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-backend
    # 表示服务之间的启动和关闭依赖关系。
    depends_on:
      soil-redis:
        condition: service_healthy
      soil-elasticsearch:
        condition: service_healthy
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost:8080/actuator/health | grep -q '^{\"status\":\"UP\"'" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-backend
    # 指定启动容器的图像。
    #    image: soil-backend:0.0.1-SNAPSHOT
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "8080:8080"
    # 定义平台在容器终止时应用的策略。
    restart: always
  soil-nginx:
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-nginx
    # 表示服务之间的启动和关闭依赖关系。
    depends_on:
      soil-backend:
        condition: service_healthy
    # 声明运行以确定该服务的容器是否“健康”的检查。
    healthcheck:
      test: [ "CMD-SHELL", "curl http://localhost:80 | grep -q '^<!doctype html>'" ]
      # 运行状况检查将在容器启动后首先运行间隔秒,然后在之前的每个检查完成后再次运行间隔秒。
      interval: 10s
      # 如果单次运行检查花费的时间超过超时秒数,则检查被视为失败。
      timeout: 10s
      # 需要重试健康检查连续失败才能将容器视为不健康。
      retries: 3
      # 为需要时间引导的容器提供初始化时间。
      start_period: 40s
    # 声明用于服务容器的自定义主机名。
    hostname: soil-nginx
    # 指定启动容器的图像。
    image: nginx:1.25.3
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "80:80"
    # 定义平台在容器终止时应用的策略。
    restart: always
    # 定义服务容器必须可以访问的挂载主机路径或命名卷。
    volumes:
      - ./docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/docs/html:/etc/nginx/docs/html
  soil-portainer:
    # 指定自定义容器名称,而不是生成的默认名称。
    container_name: soil-portainer
    # 声明用于服务容器的自定义主机名。
    hostname: soil-portainer
    # 指定启动容器的图像。
    image: portainer/portainer-ce:2.19.4
    # 定义服务容器附加到的网络,引用顶级网络键下的条目。
    networks:
      - soil
    # 暴露端口。 指定两个端口 (HOST:CONTAINER),或仅指定容器端口(选择临时主机端口)。
    ports:
      - "9000:9000"
      - "9443:9443"
    # 定义平台在容器终止时应用的策略。
    restart: always
    # 定义服务容器必须可以访问的挂载主机路径或命名卷。
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值