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

Jenkins2019inDocker(1)InstallSingleAppinDocker

YoucanfindtheDockerinformationherehttps://hub.docker.com/r/jenkins/jenkins

IlikethiscommandtogettheLTSversion

>dockerpulljenkins/jenkins:lts

ThenIpreparethisMakefiletomakeitsimple

PORT=9091

IMAGE=docker.io/jenkins/jenkins

TAG=lts

NAME=jenkins-$(PORT)

run:

dockerrun-d-p$(PORT):8080-p50000:50000-v$(shellpwd)/jenkins:/var/jenkins_home--name$(NAME)$(IMAGE):$(TAG)

clean:

dockerstop${NAME}

dockerrm${NAME}

StarttheJenkinsonmyLocal

>makerun

VisittheUI

http://localhost:9091

Gotomydirectoryandfindthepasswordtherejenkins/secrets/initialAdminPassword

Thisnicecommandcanrunonthehostmachinetocatthecontentinsidedockerapplication

>dockerexecjenkins-9091cat/var/jenkins_home/secrets/initialAdminPassword

2aca09ea79f041edxxxxx

Installthesuggestedplugins,theLTSversionisJenkins2.150.2

Theinstallationiscool.

Goinsidethedockernode

>dockerexec-it-urootjenkins-9091bash

Thewarpackageishereinsidethedocker

/usr/share/jenkins/jenkins.war

Upgradethewarpackageifweneed.Downloadthelatestwar

>wgethttp://mirrors.jenkins.io/war/latest/jenkins.war-Pinstall/

Copymywarpackagethere

>dockercpinstall/jenkins.warjenkins-9091:/usr/install/

Replacethewarwiththelatestone

>cd/usr/share/jenkins/

>cpjenkins.warjenkins.war.bak

>cp/usr/install/jenkins.war/usr/share/jenkins/jenkins.war

RestarttheJenkins.Jenkinsisrunningthere

>java-Duser.home=/var/jerkins_home-jar/usr/share/jenkins/jenkins.war--httpPort=9090

Restartthejenkins

http://localhost:9091/restart

Afterupgrade,theversionisJenkinsver.2.160

UseGenericWaytoRuninDocker

start.shtostartthejenkinsprocess

#!/bin/sh-ex

cd/tool/

java-Duser.home=/var/jenkins_home-jarjenkins.war

Dockerfiletopreparealldependencies

#SetUpJenkinsCI

#PrepretheOS

FROMcentos:7

MAINTAINERCarlLuo<luohuazju@gmail.com>

#installthesoftware

RUNyum-yupdate

RUNyuminstall-yjava-1.8.0-openjdk-devel

#installjenkins

RUNmkdir-p/tool/

ADDinstall/jenkins.war/tool/

WORKDIR/tool/

#starttheapplication

EXPOSE808050000

RUNmkdir-p/app/

ADDstart.sh/app/

WORKDIR/app/

CMD["./start.sh"]

Makefiletosummarizeallthecommands

PORT=9092

IMAGE=sillycat/public

TAG=lablue-jenkins-generic

NAME=jenkins-generic-$(PORT)

prepare:

wgethttp://ftp-nyc.osuosl.org/pub/jenkins/war-stable/2.150.2/jenkins.war-Pinstall/

docker-context:

build:docker-context

dockerbuild-t$(IMAGE):$(TAG).

run:

dockerrun-d-p$(PORT):8080-p50000:50000-v$(shellpwd)/jenkins_home:/var/jenkins_home--name$(NAME)$(IMAGE):$(TAG)

clean:

dockerstop${NAME}

dockerrm${NAME}

logs:

dockerlogs${NAME}

jenkins_homeisthebackupandrestoredirectoryweneedtocareabout.

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/

相关推荐