`
sillycat
  • 浏览: 2564746 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Jenkins 2019 in Docker(1)Install Single App in Docker

 
阅读更多
Jenkins 2019 in Docker(1)Install Single App in Docker
You can find the Docker information here https://hub.docker.com/r/jenkins/jenkins
I like this command to get the LTS version
> docker pull jenkins/jenkins:lts
Then I prepare this Makefile to make it simple
PORT=9091
IMAGE=docker.io/jenkins/jenkins
TAG=lts
NAME=jenkins-$(PORT)

run:
    docker run -d -p $(PORT):8080 -p 50000:50000 -v $(shell pwd)/jenkins:/var/jenkins_home --name $(NAME) $(IMAGE):$(TAG)
clean:
    docker stop ${NAME}
    docker rm ${NAME}
Start the Jenkins on my Local
>make run
Visit the UI
http://localhost:9091
Go to my directory and find the password there  jenkins/secrets/initialAdminPassword
This nice command can run on the host machine to cat the content in side docker application
> docker exec jenkins-9091 cat /var/jenkins_home/secrets/initialAdminPassword
2aca09ea79f041edxxxxx
Install the suggested plugins, the LTS version is Jenkins 2.150.2
The installation is cool.
Go inside the docker node
> docker exec -it -u root jenkins-9091 bash
The war package is here in side the docker
/usr/share/jenkins/jenkins.war
Upgrade the war package if we need. Download the latest war
> wget http://mirrors.jenkins.io/war/latest/jenkins.war -P install/
Copy my war package there
> docker cp install/jenkins.war jenkins-9091:/usr/install/
Replace the war with the latest one
> cd /usr/share/jenkins/
> cp jenkins.war jenkins.war.bak
> cp /usr/install/jenkins.war /usr/share/jenkins/jenkins.war
Restart the Jenkins. Jenkins is running there
> java -Duser.home=/var/jerkins_home -jar /usr/share/jenkins/jenkins.war --httpPort=9090
Restart the jenkins
http://localhost:9091/restart
After upgrade, the version is Jenkins ver. 2.160
Use Generic Way to Run in Docker
start.sh to start the jenkins process
#!/bin/sh -ex
cd /tool/
java -Duser.home=/var/jenkins_home -jar jenkins.war
Dockerfile to prepare all dependencies
#Set Up Jenkins CI
#Prepre the OS
FROM centos:7
MAINTAINER Carl Luo <luohuazju@gmail.com>
#install the software
RUN yum -y update
RUN yum install -y java-1.8.0-openjdk-devel
#install jenkins
RUN      mkdir -p /tool/
ADD        install/jenkins.war /tool/
WORKDIR /tool/
#start the application
EXPOSE  8080 50000
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app/
CMD    [ "./start.sh" ]
Makefile to summarize all the commands
PORT=9092
IMAGE=sillycat/public
TAG=lablue-jenkins-generic
NAME=jenkins-generic-$(PORT)
prepare:
    wget http://ftp-nyc.osuosl.org/pub/jenkins/war-stable/2.150.2/jenkins.war -P install/
docker-context:
build: docker-context
    docker build -t $(IMAGE):$(TAG) .
run:
    docker run -d -p $(PORT):8080 -p 50000:50000 -v $(shell pwd)/jenkins_home:/var/jenkins_home --name $(NAME) $(IMAGE):$(TAG)
clean:
    docker stop ${NAME}
    docker rm ${NAME}
logs:
    docker logs ${NAME}
jenkins_home is the backup and restore directory we need to care about.

References:
https://www.jianshu.com/p/0391e225e4a6
http://www.sunlins.cn/2018/11/19/%E3%80%90jenkinsdocker%E3%80%9102-%E5%8D%87%E7%BA%A7docker%E6%96%B9%E5%BC%8F%E5%AE%89%E8%A3%85jenkins%E7%9A%84%E7%89%88%E6%9C%AC/
https://hub.docker.com/_/jenkins/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics