What does “RUN sh -c 'touch /app.jar'” do?

2019-06-14 06:59发布

Can somebody explain to me why this line is required and what this line is doing?

RUN sh -c 'touch /app.jar'

The full docker file lookes like this and in every templanete it can be found.

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD docker-example-service-1.0.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 8080
ENV JAVA_OPTS=""
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-Dapp.port=${app.port}", "-jar","/app.jar"]

2条回答
乱世女痞
2楼-- · 2019-06-14 07:26

touch command will update the timestamp to file, directory.

So that you can keep track of files when it's get created and updated.

RUN sh -c 'touch /app.jar'

when you invoke docker build, above command will update timestamp to app.jar.

For complete details of touch command refer below link https://www.computerhope.com/unix/utouch.htm

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-14 07:43

touch is a standard Unix command-line interface program which is used to update the access date and or modification date of a file or directory. [...] Touch can also be useful for quickly creating files for programs or scripts that require a file with a specific name to exist for successful operation of the program, but do not require the file to have any specific content.

Wikipedia

In your case it's most likely that the touch command is used to ensure that the file exists.

查看更多
登录 后发表回答