如何在容器中注入Docker容器构建时间戳? [英] How to inject Docker container build timestamp in container?
本文介绍了如何在容器中注入Docker容器构建时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想构建一个在其启动日志中显示其构建日期时间的容器。有没有办法将信息从我的构建机器注入到容器中?
I would like to build a container which shows up in its startup log its build datetime. Is there a way to have that information injected from my build machine into the container ?
推荐答案
在运行过程中每个RUN步骤的输出build是对文件系统的更改。因此,您可以将日期输出到图像中的文件。容器中的日志只是您运行的命令的标准输出。这样,您就可以在入口点中列出日期了。
The output of each RUN step during a build is the changes to the filesystem. So you can output the date to a file in your image. And the logs from the container are just the stdout from commands you run. So you can cat out the date inside your entrypoint.
在代码中,您将在Dockerfile的末尾:
In code, you'd have at the end of your Dockerfile:
RUN date >/build-date.txt
在入口点脚本中:
#!/bin/sh
#.... Initialization steps
echo Image built: $(cat /build-date.txt)
#.... More initialization steps
# run the command
exec "$@"
这篇关于如何在容器中注入Docker容器构建时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文