1、准备
打包后包名为 ruoyi-admin.jar
增加接口 httpL//{ip}:{port}/common/test/han
#环境变量预application.yml 中REDIS_HOSTt的值,去环境变量去找;如果找不到REDIS_HOST就用myredis
1、Dockerfile
FROM hlw/java:8-jre
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /aaaa
WORKDIR /aaaa
EXPOSE 7979
ENV 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_6379
image: redis:6.0.6
restart: always
ports:
- 6379:6379
privileged: true
command: redis-server /etc/redis/redis.conf --appendonly yes
volumes:
- $PWD/redis/data:/data:rw
- $PWD/redis/conf/redis.conf:/etc/redis/redis.conf:rw
networks:
- qingcheweb
myService:
container_name: service_test
build: ./springboot
restart: always
environment:
#环境变量预application.yml 中redis->host的值;如果找不到REDIS_HOST就用myredis
- REDIS_HOST = 39.105.156.105
ports:
- "8088:8080"
depends_on:
- myredis
links:
- myredis
volumes:
- /home/sqmydzf/ruoyi:/home/sqmydzf/ruoyi:rw
networks:
- qingcheweb
networks:
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-jre
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /aaaa
WORKDIR /aaaa
EXPOSE 7979
ENV 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、启动文章来源:https://www.toymoban.com/news/detail-641651.html
[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、测试文章来源地址https://www.toymoban.com/news/detail-641651.html
[root@izwz91uabta2x8pfjc2wzsz docker]# curl http://127.0.0.1:8088/common/test/han
{"msg":"hello,han","code":200}
到了这里,关于七、dokcer-compose部署springboot的jar的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!