栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

Docker Config 管理 Spring Boot 应用配置

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker Config 管理 Spring Boot 应用配置

1、构建 Spring Boot 应用镜像
FROM openjdk:8-jre-alpine

ADD target/*.jar app.jar

EXPOSE 8080

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

使用 ENTRYPOINT ,可在 Docker 命令后面添加额外参数,
比如 --server.port=8888 等等

2、创建 Docker config

不同环境、不同应用创建不同的配置

此处用可视化工具来创建是为了更方便的维护配置,当然也可以用命令行来创建,结合实际选择合适的方式。

3、创建服务,依赖配置
docker service create 
     --name  
     --config source=dev-spring-boot,target=/application.yaml 
     --publish published=8080,target=8080       
     --spring.config.location=file:/application.yaml
  • --config 将 docker config 安装到容器的文件系统,路径 /application.yaml

  • --spring.config.location=file:/application.yaml 指定 Spring Boot 应用启动使用的配置文件为 /application.yaml

如果要覆盖某个配置项,只需在后面添加 --key=value 即可,示例:

docker service create 
     --name  
     --config source=dev-spring-boot,target=/application.yaml 
     --publish published=8080,target=8080       
     --spring.config.location=file:/application.yaml  
     --logging.level=debug



作者:Anoyi
链接:https://www.jianshu.com/p/49155f18884c


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/235431.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号