1、准备
打包后包名为 ruoyi-admin.jar
增加接口 httpL//{ip}:{port}/common/test/han
#环境变量预application.yml 中REDIS_HOSTt的值,去环境变量去找;如果找不到REDIS_HOST就用myredis
1、Dockerfile
FROM hlw/java:8-jreRUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezoneRUN mkdir -p /aaaaWORKDIR /aaaaEXPOSE 7979ENV TZ=Asia/Shanghai ENV JAVA_OPTS="-Xms512m -Xmx1024m -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"ADD ./target/ruoyi-admin.jar ./CMD sleep 20;java $JAVA_OPTS -jar ruoyi-admin.ja
2、docker-compose.yml
version: '3.8'
services:myredis:container_name: redis_6379image: redis:6.0.6restart: alwaysports:- 6379:6379privileged: truecommand: redis-server /etc/redis/redis.conf --appendonly yesvolumes:- $PWD/redis/data:/data:rw- $PWD/redis/conf/redis.conf:/etc/redis/redis.conf:rwnetworks:- qingchewebmyService:container_name: service_testbuild: ./springbootrestart: alwaysenvironment:
#环境变量预application.yml 中redis->host的值;如果找不到REDIS_HOST就用myredis- REDIS_HOST = 39.105.156.105ports:- "8088:8080"depends_on:- myredislinks:- myredisvolumes:- /home/sqmydzf/ruoyi:/home/sqmydzf/ruoyi:rwnetworks:- qingchewebnetworks:qingcheweb:driver: bridge
3、结构目录
[root@izwz91uabta2x8pfjc2wzsz docker]# tree
.
├── docker-compose.yml
├── redis
│ ├── conf
│ │ └── redis.conf
│ └── data
│ ├── appendonly.aof
│ └── dump.rdb
└── springboot├── Dockerfile└── target└── ruoyi-admin.jar
2、测试
1、构建镜像
FROM hlw/java:8-jreRUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezoneRUN mkdir -p /aaaaWORKDIR /aaaaEXPOSE 7979ENV TZ=Asia/Shanghai ENV JAVA_OPTS="-Xms512m -Xmx1024m -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom"ADD ./target/ruoyi-admin.jar ./CMD sleep 20;java $JAVA_OPTS -jar ruoyi-admin.jar
2、启动
[root@izwz91uabta2x8pfjc2wzsz docker]# docker-compose up -d
[+] Running 3/3✔ Network docker_qingcheweb Created 0.1s ✔ Container redis_6379 Started 0.5s ✔ Container service_test Started
3、测试
[root@izwz91uabta2x8pfjc2wzsz docker]# curl http://127.0.0.1:8088/common/test/han
{"msg":"hello,han","code":200}