为了账号安全,请及时绑定邮箱和手机立即绑定

Docker Config 管理 Spring Boot 应用配置

标签:
Docker

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 <ServiceName> \
     --config source=dev-spring-boot,target=/application.yaml \
     --publish published=8080,target=8080 \     <Image> \
     --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 <ServiceName> \
     --config source=dev-spring-boot,target=/application.yaml \
     --publish published=8080,target=8080 \     <Image> \
     --spring.config.location=file:/application.yaml \ 
     --logging.level=debug

相关资料



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

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消