另一种办法直接在宿主机上的文件夹内查看Docker镜像运行的日志文件

举报
Jerry Wang 发表于 2022/02/21 21:45:12 2022/02/21
【摘要】 我们可以用docker ps首先找到某个Docker容器的id,再使用关键字docker logs <容器id>打印出该容器产生的日志:同样,在宿主机目录/var/lib/docker/containers下面,能发现一个文件夹,其前12位名称正好是我们在命令docker ps里查看到的容器id:进入该文件夹,即可查找到以-json.log结尾的日志文件:如何将SpringBoot应用Doc...

我们可以用docker ps首先找到某个Docker容器的id,再使用关键字docker logs <容器id>打印出该容器产生的日志:


同样,在宿主机目录/var/lib/docker/containers下面,能发现一个文件夹,其前12位名称正好是我们在命令docker ps里查看到的容器id:

进入该文件夹,即可查找到以-json.log结尾的日志文件:


如何将SpringBoot应用Docker化并部署到SAP云平台?

首先需要把SpringBoot应用打包成docker,我用的dockerfile内容为:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
VOLUME /log
EXPOSE 8080
ADD target/prolikeService.jar app.jar
ENV JAVA_OPTS="-Dserver.port=8080"
ENTRYPOINT exec java $JAVA_OPTS -jar /app.jar

使用如下的命令行打包:

docker build -t i042416/springbootexample:v4 .

docker login登录docker hub,将该镜像上传:

docker push i042416/springbootexample:v4

最后使用命令部署到SAP Cloud Platform上:

cf push jerryjavadocker --docker-image i042416/springbootexample:v4



命令执行完毕后,能够在SAP云平台的控制台里,看到这个成功部署的Docker应用:

从控制台里得到应用url:

成功访问:

SpringBoot里的官方文档叫做Externalized Configuration:

优先级依次如下:

(1) Devtools global settings properties in the $HOME/.config/spring-boot folder when devtools is active.

(2) @TestPropertySource annotations on your tests.

(3) properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.

(4) Command line arguments.

(5) Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).

(6) ServletConfig init parameters.

(7) ServletContext init parameters.

(8) JNDI attributes from java:comp/env.

(9) Java System properties (System.getProperties()).

(10) OS environment variables.

(11) A RandomValuePropertySource that has properties only in random.*.

(12) Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).

(13) Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).

(14) Application properties outside of your packaged jar (application.properties and YAML variants).

(15) Application properties packaged inside your jar (application.properties and YAML variants).

(16) @PropertySource annotations on your @Configuration classes. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins.

(17) Default properties (specified by setting SpringApplication.setDefaultProperties).

做个实验,在run as configuration里,program argument设置为server.port=8001,

Environment环境变量设置为server.port=8002.

在SpringBoot项目内部的Application.properties文件设置成8000:

最后运行时,生效的端口是环境变量设置进去的8002:


在shell里使用set命令设置环境变量,也能按照期望的方式工作:


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。