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"]
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
Wikipedia
In your case it's most likely that the
touch
command is used to ensure that the file exists.