首先先准备好项目jar包和Dockfile文件
Dockfile文件配置如下:
点击查看代码
# 拉取基础镜像
FROM openjdk:11
# 类似于作者
MAINTAINER dpf
# 创建镜像目录
RUN mkdir -p /htht/server/logs \
/htht/server/temp \
/htht/skywalking/agent
# 工作区
WORKDIR /htht/server
# 挂载目录
VOLUME /htht/server
# 指定端口
ENV SERVER_PORT=9999
# 端口暴露
EXPOSE ${SERVER_PORT}
# 将dockerfile当前文件夹下的/usr/server/golmud.jar 复制添加到容器镜像中的golmud.jar目录下
ADD ./jar/golmud.jar /htht/server/golmud.jar
ADD ./jar/logs /htht/server/logs
# 启动指令
ENTRYPOINT ["java", \
"-Djava.security.egd=file:/dev/./urandom", \
"-Dserver.port=${SERVER_PORT}", \
# 应用名称 如果想区分集群节点监控 改成不同的名称即可
# "-Dskywalking.agent.service_name=ruoyi-server", \
# "-javaagent:/ruoyi/skywalking/agent/skywalking-agent.jar", \
"-jar", "golmud.jar"]
点击查看代码
docker pull openjdk:11
docker images openjdk:11
# 镜像导出
docker save -o 文件.tar 镜像名称
将tar文件下载到本地,本地将文件传输到离线服务器
离线服务器得先有离线docker环境
# 镜像导入
通过 docker load -i 文件.tar
# 查看镜像是否成功导入
docker images openjdk:11
点击查看代码
mkdir -p /usr/dpf/jar
# 将jar包、log文件夹 放到该目录/usr/dpf/jar下
cd /usr/dpf
# 将Dockerfile文件 放到/usr/dpf/下
# 镜像打包
docker build -t 自定义镜像名称 .
# 查看镜像是否打包成功
docker images 自定义镜像名称
点击查看代码
version: '3.0'
services:
soil-postgres:
image: kartoza/postgis:13-3.1
container_name: soil-postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres密码
ALLOW_IP_RANGE: 0.0.0.0/0
expose:
- "5432"
ports:
- "18082:5432"
volumes:
- "../apps/postgis13/data:/var/lib/postgresql"
- /etc/localtime:/etc/localtime
networks:
- soil-network
soil-redis:
image: redis:6.2.7
container_name: soil-redis
restart: always
expose:
- "6379"
# ports:
# - "16379:6379"
environment:
# 时区上海
TZ: Asia/Shanghai
volumes:
# 配置文件
- "../apps/redis/conf:/redis/config:rw"
# 数据文件
- "../apps/redis/data/:/redis/data/:rw"
command: "redis-server /redis/config/redis.conf"
privileged: true
networks:
- soil-network
soil-nginx:
image: nginx:1.22.1
container_name: soil-nginx
restart: always
environment:
- LANG=en_US.UTF-8
ports:
# - "18080:80"
- "18080:443"
volumes:
- "../apps/nginx/nginx.conf:/etc/nginx/nginx.conf"
- "../apps/nginx/cert:/etc/nginx/cert"
- "../apps/nginx/conf.d:/etc/nginx/conf.d"
- "../apps/nginx/logs:/var/log/nginx"
- "../apps/nginx/html:/usr/share/nginx/html"
- /etc/localtime:/etc/localtime
networks:
- soil-network
golmud:
image: golmud:1.0
container_name: golmud
environment:
# redis
REDIS_HOST: soil-redis
REDIS_PORT: 6379
REDIS_PWD: redis密码
expose:
- "9999"
volumes:
- /usr/dpf/logs/:/htht/server/logs/
- /usr/dpf/jar/:/htht/server/
networks:
- soil-network
soil-geoserver:
image: kartoza/geoserver:2.16.2
container_name: soil-geoserver
restart: always
privileged: true
expose:
- "8080"
- "8443"
ports:
- "18083:8443"
volumes:
- "../apps/geoserver/data_dir:/opt/geoserver/data_dir"
- "../apps/geoserver/web.xml:/usr/local/tomcat/webapps/geoserver/WEB-INF/web.xml"
- "../apps/geoserver/fonts/chinese:/usr/share/fonts/chinese"
- /etc/localtime:/etc/localtime
networks:
- soil-network
networks:
soil-network:
driver: bridge
其中镜像:
kartoza/postgis:13-3.1
nginx:1.22.1
golmud:1.0(jar包的应用镜像)
redis:6.2.7
kartoza/geoserver:2.16.2
通过docker load -i 文件.tar的形式需要提前装载好
在docker-compose.yaml文件夹下后台启动服务
docker-compose up -d
配置nginx
由于做了配置映射
../apps/nginx/nginx.conf:/etc/nginx/nginx.conf
点击查看代码
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 限制body大小
client_max_body_size 100m;
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 /var/log/nginx/access.log main;
# 业务
upstream geoserver {
server soil-geoserver:18083;
}
upstream server2 {
server golmud:9999;
}
server {
listen 80;
# https配置参考 start
# listen 443 ssl;
server_name localhost;
# 限制外网访问内网 actuator 相关路径
location ~ ^(/[^/]*)?/actuator(/.*)?$ {
return 403;
}
# 大屏
location /golmud/ {
alias /usr/share/nginx/html/golmud/screen/;
index index.html index.htm;
}
# 后台
location /golmud-admin/ {
alias /usr/share/nginx/html/golmud/admin/;
index index.html index.htm;
}
location /golmud-agriculture/ {
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://server2/;
}
location /geoserver {
proxy_cookie_path / "/; secure; HttpOnly; SameSite=None";
# proxy_set_header Cookie $http_cookie;
add_header backendIP $upstream_addr;
add_header backendCode $upstream_status;
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_set_header X-Forwarded-Host $Server_name;
proxy_connect_timeout 30s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
proxy_buffering off;
proxy_pass http://geoserver/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
补充nginx中 root和alias的区别
点击查看代码
假设 root 情况下
location /a/b/ {
root /c/img/;
}
访问 http://ip地址:端口/java/a/b/1.png 会跳转成=> http://ip地址:端口/java/c/img/a/b/1.png
假设 alias情况下 (alias指定的路径后面一定要加/)
location /a/b/ {
alias /c/img/;
}
访问 http://ip地址:端口/java/a/b/1.png 会跳转成=> http://ip地址:端口/java/c/img/1.png