docker.build jenkins code example
Example 1: how to upgrade jenkins in docker
mkdir -p $HOME/jenkins
docker container run \
--name jenkins \
-p 8080:8080 -p 50000:50000 \
-v $HOME/jenkins:/var/jenkins_home \
-d \
jenkins
docker container exec -u 0 -it jenkins bash
wget http://updates.jenkins-ci.org/download/war/2.89.2/jenkins.war
mv ./jenkins.war /usr/share/jenkins
exit
docker container restart jenkins
chown jenkins:jenkins /usr/share/jenkins/jenkins.war (updated)
exit
docker container restart jenkins
docker volume create jenkins-data
docker run --name jenkins-production \
--detach \
-p 50000:50000 \
-p 8080:8080 \
-v jenkins-data:/var/jenkins_home \
jenkins/jenkins:2.107.3
docker exec jenkins-production bash -c 'cat $JENKINS_HOME/secrets/initialAdminPassword'
docker stop jenkins-production
docker rm jenkins-production
docker run --name jenkins-production \
--detach \
-p 50000:50000 \
-p 8080:8080 \
-v jenkins-data:/var/jenkins_home \
jenkins/jenkins:2.121.3
Example 2: docker run jenkins
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts