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、启动
[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}