I think I know what is going on. Here is the Dockerfile I was using to figure out what was going on (copied from above):
FROM jenkins/jenkins:lts
RUN ls -l /var/jenkins_home/; touch /var/jenkins_home/isthisworking; echo "================================"; ls -l /var/jenkins_home;
As mentioned, with this file, at build time, I would see the file isthisworking
but when I run the container, that file is no longer there.
So I went to jenkins/jenkins:lts github page and looked at their Dockerfile. I saw this on line 26:
# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
VOLUME $JENKINS_HOME
Here, $JENKINS_HOME
is /var/jenkins_home/
. So as a Docker noob, I asked myself what is VOLUME
(I know what it is from the command line but not inside a Dockerfile)? With googling, I found this and this, which basically say:
The docker run command initializes the newly created volume with any
data that exists at the specified location within the base image.
Since that location is a docker VOLUME at that point in the Dockerfile, no matter what and how files are copied into it, at container runtime that location will be reinitialized to how the base image has it "defined."
To have the file stay when the container is run, make the modification/addition to the directory prior to making it a VOLUME.