有的项目写完,需要打包到不同的环境。所以配置一个外部 yml 配置文件会方便很多,不用重新打包。
文件目录构造
├──app├──application.yml
├──app.jar
├──Dockerfile
├──mysql
├──nginx
docker-compose.yml
w.sh
Dockerfile
FROM java:8
#VOLUME /tmp
ADD dstapp.jar app.jar
ADD application.yml /application.yml
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-Dspring.config.location=/application.yml", "-jar", "/app.jar"]
注意,以上顺序不可改变。-Dspring.config.location 别搞错了,不是 --spring.config.location
docker-compose.yml
version : '2'
services:
redis:
image: redis:3
command: redis-server --requirepass 1234
ports:
- "6379"
nginx:
build: nginx
image: jo/nginx
ports:
- "9527:9527"
volumes:
- ./nginx/dist/:/etc/nginx/html/
links:
- dstapp
mysql:
build: mysql
image: jo/mysql
volumes:
- ./src/main/docker/mysql/my.cnf:/root/mysql/my.cnf mysql
command: --max_allowed_packet=32505856
environment:
- MYSQL_ROOT_PASSWORD=123456
ports:
- "3306"
expose:
- "3306"
dstapp:
build: dstapp
image: jo/dstapp
volumes:
- ./w.sh:/w.sh
ports:
- "8080"
restart: always
depends_on:
- mysql
links:
- mysql
- redis
entrypoint: "./w.sh mysql:3306 -- java -Dspring.config.location=/application.yml -jar /app.jar"
注意:这里的 -Dspring.config.location 也是需要注意位置。
标签:compose,java,application,jar,nginx,location,mysql,docker,yml From: https://www.cnblogs.com/gaoyanbing/p/17785368.html