Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Created June 13, 2018 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save managedkaos/b869c2eef12345da1d431976ba350b0f to your computer and use it in GitHub Desktop.
Save managedkaos/b869c2eef12345da1d431976ba350b0f to your computer and use it in GitHub Desktop.
Run Jenkins on Docker
function jenkinsondocker() {
if [ $(ps -elf | grep docker | wc -l) -gt 0 ];
then
echo -n $(docker stop jenkins 2>&1) | sed 's/Error response from daemon://'
echo -n $(docker rm jenkins 2>&1) | sed 's/Error response from daemon://'
docker pull jenkins/jenkins:lts
docker run --detach --publish 49000:8080 --name jenkins jenkins/jenkins:lts
echo -n "Waiting for Jenkins process to start ."
until [ $(curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://127.0.0.1:49000) -eq 403 ]; do echo -n '.'; sleep 1; done
echo
echo -n "Here's the admin password! "
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
echo "Browse to http://localhost:49000"
else
echo "Can't find any docker processes. Is Docker really running? :/"
fi
}
@managedkaos
Copy link
Author

Put this in your .bashrc and then run

jenkinsondocker

you'll see:

jenkins
jenkins
lts: Pulling from jenkins/jenkins
cc1a78bfd46b: Already exists
d2c05365ee2a: Pull complete
231cb0e216d3: Pull complete
3d2aa70286b8: Pull complete
b621e52d9d65: Pull complete
f12314f6054a: Pull complete
f5ce6397976f: Pull complete
965859e0769b: Pull complete
4a76f2995e39: Pull complete
0de631c380d1: Pull complete
9d6752920dc9: Pull complete
c406b862fb45: Pull complete
540e374a8d0d: Pull complete
7be67aad290d: Pull complete
f6fd454b745e: Pull complete
ccc2b3edf0f8: Pull complete
28805657226a: Pull complete
3738af7c03c4: Pull complete
dab16bb6b3f9: Pull complete
aa4f9c274e44: Pull complete
5d8390d0a2de: Pull complete
Digest: sha256:30793c79d6f59467bb8b821a8bc96cda24a61397f54658adb25825c68f8d464f
Status: Downloaded newer image for jenkins/jenkins:lts
6400d7ed966058420c956003e136024a957b4b274ab15ee803776b183a239e7d
Waiting for Jenkins process to start ..........
Here's the admin password!   bebaee6349f74952a3ea062018aee52a
Browse to http://localhost:49000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment