Home > Net >  Why does docker image content differ from the container created from it?
Why does docker image content differ from the container created from it?

Time:01-23

Following is the Dockerfile for the image,

FROM jenkins/jenkins:lts-jdk11
USER jenkins
RUN jenkins-plugin-cli --plugins "blueocean:1.25.2 http_request" && ls -la /var/jenkins_home

When this is built using docker build -t ireshmm/jenkins:lts-jdk11 ., following is the output,

Sending build context to Docker daemon  3.072kB
Step 1/3 : FROM jenkins/jenkins:lts-jdk11
 ---> 9aee0d53624f
Step 2/3 : USER jenkins
 ---> Using cache
 ---> 49d657d24299
Step 3/3 : RUN jenkins-plugin-cli --plugins "blueocean:1.25.2 http_request" && ls -la /var/jenkins_home
 ---> Running in b459c4c48e3e
Done
total 20
drwxr-xr-x 3 jenkins jenkins 4096 Jan 22 16:49 .
drwxr-xr-x 1 root    root    4096 Jan 12 15:46 ..
drwxr-xr-x 3 jenkins jenkins 4096 Jan 22 16:49 .cache
-rw-rw-r-- 1 jenkins root    7152 Jan 12 15:42 tini_pub.gpg
Removing intermediate container b459c4c48e3e
 ---> 5fd5ba428f1a
Successfully built 5fd5ba428f1a
Successfully tagged ireshmm/jenkins:lts-jdk11

When create a container and list files docker run -it --rm ireshmm/jenkins:lts-jdk11 ls -la /var/jenkins_home, following is the output:

total 40
drwxr-xr-x 3 jenkins jenkins  4096 Jan 22 16:51 .
drwxr-xr-x 1 root    root     4096 Jan 12 15:46 ..
-rw-r--r-- 1 jenkins jenkins  4683 Jan 22 16:51 copy_reference_file.log
drwxr-xr-x 2 jenkins jenkins 16384 Jan 22 16:51 plugins
-rw-rw-r-- 1 jenkins root     7152 Jan 12 15:42 tini_pub.gpg

Question: Why do the contents of /var/jenkins_home differ while building the image and the inside the container created from it given that no command is run after listing the files while building image? How can that happen?

CodePudding user response:

The jenkins/jenkins:lts-jdk11 has an ENTRYPOINT that runs /usr/local/bin/jenkins.sh, which among other things creates the copy_reference_file.log file:

$ grep -i copy_reference /usr/local/bin/jenkins.sh
: "${COPY_REFERENCE_FILE_LOG:="${JENKINS_HOME}/copy_reference_file.log"}"
touch "${COPY_REFERENCE_FILE_LOG}" || { echo "Can not write to ${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?"; exit 1; }
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
find "${REF}" \( -type f -o -type l \) -exec bash -c '. /usr/local/bin/jenkins-support; for arg; do copy_reference_file "$arg"; done' _ {}  

The ENTRYPOINT scripts runs whenever you start a container from that image (before any command you've provided on the command line).

  •  Tags:  
  • Related