自学内容网 自学内容网

docker部署nginx+nacos+redis+java镜像和容器

  1. nginx镜像制作

    Dockerfile内容:

    # 基础镜像
    FROM nginx
    # author
    MAINTAINER ruoyi
    
    # 挂载目录
    VOLUME /home/ruoyi/projects/ruoyi-ui
    # 创建目录
    RUN mkdir -p /home/ruoyi/projects/ruoyi-ui
    # 指定路径
    WORKDIR /home/ruoyi/projects/ruoyi-ui
    # 复制conf文件到路径
    COPY ./conf/nginx.conf /etc/nginx/nginx.conf
    # 复制html文件到路径
    COPY ./html/dist /home/ruoyi/projects/ruoyi-ui

    nginx.conf

    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    
        server {
            listen       80;
            server_name  localhost;
    
            location / {
                root   /home/ruoyi/projects/ruoyi-ui;
                try_files $uri $uri/ /index.html;
                index  index.html index.htm;
            }
    
            location /prod-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://ruoyi-gateway:8080/;
            }
    
            # 避免actuator暴露
            if ($request_uri ~ "/actuator") {
                return 403;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

  2. nacos镜像制作

application.properties 

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://ruoyi-mysql:3306/nacos-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=password

nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000

management.endpoints.web.exposure.include=*

management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

server.tomcat.basedir=/home/ruoyi/nacos/tomcat/logs

nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=false
nacos.core.auth.default.token.expire.seconds=18000
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security

nacos.istio.mcp.server.enabled=false

 Dockerfile文件:

# 基础镜像
FROM nacos/nacos-server
# author
MAINTAINER ruoyi

# 复制conf文件到路径
COPY ./conf/application.properties /home/nacos/conf/application.properties

3 redis

Dockerfile:

# 基础镜像
FROM redis
# author
MAINTAINER ruoyi

# 挂载目录
VOLUME /home/ruoyi/redis
# 创建目录
RUN mkdir -p /home/ruoyi/redis
# 指定路径
WORKDIR /home/ruoyi/redis
# 复制conf文件到路径
COPY ./conf/redis.conf /home/ruoyi/redis/redis.conf

 redis.conf:

requirepass 123456

4 java jar服务部署

Dockerfile内容:

# 基础镜像
FROM  openjdk:8-jre
# author
MAINTAINER ruoyi

# 挂载目录
VOLUME /home/ruoyi
# 创建目录
RUN mkdir -p /home/ruoyi
# 指定路径
WORKDIR /home/ruoyi
# 复制jar文件到路径
COPY ./jar/ruoyi-auth.jar /home/ruoyi/ruoyi-auth.jar
# 启动认证服务
ENTRYPOINT ["java","-jar","ruoyi-auth.jar"]

 


原文地址:https://blog.csdn.net/xiaogg3678/article/details/143431245

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!