docker - Dockerfile 中的 `touch` 有什么作用?
问题描述
解决方案
Because of Docker layer caching, in a lot of common cases the touch
command won't do anything. If the jar file has changed then the ADD command will include it in the image with its last-modified time from the host ("it is copied individually along with its metadata"); since that's presumably recently, the touch
command will update it to seconds later. If the jar file hasn't changed then Docker will skip both the ADD and RUN commands and use the filesystem output from the previous time you ran it, with the previous run's timestamp.
If the jar file is just being used as an input to java -jar
then its last-modified time shouldn't be relevant to anything either.
I'd guess you can safely remove the touch
command with no ill effects. There are a couple of unnecessary sh -c
invocations that don't matter and just clutter things. I'd guess this Dockerfile to be functionally equivalent:
# Prefer COPY to ADD, unless you explicitly want Docker to fetch
# URLs or unpack archives
COPY dist /dist/
ARG JAR_FILE
COPY target/${JAR_FILE} /target/app.jar
EXPOSE 8080
# Prefer CMD to ENTRYPOINT, if nothing else so `docker run imagename sh` works
# Split simple commands into words yourself
CMD ["java", "-jar", "/target/app.jar"]
推荐阅读
- javascript - Axios createError.js:16 Uncaught (in promise) 错误:请求失败,状态码 400
- python - Vaex 无法打开 pandas 创建的 hdf5
- kubernetes - 无法通过 Tekton 的入门。TaskRun 并没有真正运行
- html - 根据 Angular 中的另一个下拉选择更改并显示下拉值
- android - createUserWithEmailandPassword().addOnCompleteListener() 不起作用
- rust - 如何将使用单态化(静态调度)的结构存储到另一个结构的字段中?
- python - 将图像拆分为重叠补丁的有效方法,对补丁进行数学运算,然后通过获取每个像素的最大值将图像重新合并在一起
- java - 转换数组列表
到没有 GSON 的 JSONObject - javascript - HTML 锚链接中断站点/不能正常工作?
- c++ - 如何使用 MPIR Prime 测试仪 mpz_likely_prime_p 和 mpz_probable_prime_p?