1

I have following Dockerfile:

FROM jenkins/jenkins:lts
SHELL ["/bin/bash", "-c"]
ENV PROJECT_NAME Jira
ENV PROJECT_GIT_URL some_link_to_repo
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
COPY custom-template.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY ldap-config-template.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY job-dsl-template.groovy /var/jenkins_home/dsl/
COPY id_rsa /tmp/
USER root
RUN apt-get update ;\
    apt-get -y install gettext-base ;\
    cat /var/jenkins_home/dsl/job-dsl-template.groovy | envsubst > /var/jenkins_home/dsl/job-dsl.groovy ;\
    rm -v /var/jenkins_home/dsl/job-dsl-template.groovy
USER jenkins
#RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt

In jenkins/jenkins:lts there's a volume mounted in /var/jenkins_home.

Commands

cat /var/jenkins_home/dsl/job-dsl-template.groovy | envsubst > /var/jenkins_home/dsl/job-dsl.groovy ;\

and

rm -v /var/jenkins_home/dsl/job-dsl-template.groovy

looks like executed during build but I doesn't see changes made to volume /var/jenkins_home after that.

File

/var/jenkins_home/dsl/job-dsl.groovy isn't created

and /var/jenkins_home/dsl/job-dsl-template.groovy isn't removed, why?

Looks like every change made during docker image build on volume are forgeted after build.

QkiZ
  • 634
  • 2
  • 9
  • 22

1 Answers1

1

This behavior is expected as described in this answer on stackexchange. The options you have are:

  1. Hack the image metadata which isn't supported by Docker and will be overwritten when you pull the next update from upstream.
  2. Get upstream to remove the volume from their image.
  3. Build a new image based off the upstream repo with the VOLUME line removed from the Dockerfile.

Specifically for Jenkins, they've implemented their own solution, the /usr/share/jenkins/ref/ directory which gets copied to JENKINS_HOME on the first start. So your image needs to modify this folder instead of the /var/jenkins_home folder directly. You'll see this done with various scripts like install-plugins.sh and jenkins-support.

BMitch
  • 5,966
  • 1
  • 25
  • 32