Giter VIP home page Giter VIP logo

jenkins-docker's Introduction

Jenkins with Docker Build support

Get your own image badge on microbadger.com

Jenkins container supporting docker build using host's docker daemon (Docker-in-Docker).

Usage

# Linux
docker run --name jenkins -p 8080:8080 -p 50000:50000 --restart=always \
  --group-add `stat -c %g /var/run/docker.sock` \
  -v $(pwd)/jenkins_home:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  deskoh/jenkins-docker

# Windows
docker run --name jenkins -p 8080:8080 -p 50000:50000 --restart=always ^
  --group-add 0 ^
  -v %cd%/jenkins_home:/var/jenkins_home ^
  -v /var/run/docker.sock:/var/run/docker.sock ^
  deskoh/jenkins-docker

# Stop / Start / Restart
docker stop jenkins
docker start jenkins
docker restart jenkins

Jenkins default password will be in console output (stdout). Alternatively run

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword`

See official documentation for notes on using bind mount for Jenkins home directory.

Image Variants

The image variants differs by the plugins included.

latest

The following opiniated set of plugins is included:

plugins

Only Jenkins recommended plugins referenced here are included.

base

No plugins are included.

Viewing Logs

# Tail logs
docker logs -f --tail 0 jenkins

How it Works

The container is running Docker-in-Docker (DIND).

The Docker daemon listens on the /var/run/docker.sock Unix socket by default and is volume mounted to the Jenkins container. This allows the host Docker to run any Docker commands within the Jenkins container.

The jenkins user (uid 1000) needs belong to the same group (usually root) as /var/run/docker.sock on the host container to communicate with the host Docker daemon. See here for more information on uid and gid. To see the group permission for /var/run/docker.dock:

# Linux: See group permission for `/var/run/docker.dock`
$ stat -c %g /var/run/docker.sock
982

# Windows: See group permission for `/var/run/docker.dock` (on Moby Linux VM)
> docker run -it --rm -v /var/run:/var/run busybox stat -c %g /var/run/docker.sock
0

One way to achieve this is to add RUN usermod -aG root jenkins to the Dockerfile. The recommended way is to add jenkins uesr to the necessary group during runtime using --group-add parameter.

See this blog post for more details on DIND.

Adding Build Agent Nodes

See agent-docker for more details on adding build agents.

# Assuming Jenkins master is on default `jenkins-docker_default` network
docker run --network jenkins-docker_default \
  -v $(pwd)/data/worker:<remote root dir>
  deskoh/jenkins-agent-docker -url http://jenkins:8080 <secret> <worker name>

Grafana / Prometheus Monitoring

Using docker-compose.yml.

# Default grafana user/password: admin/admin

# Linux only
docker-compose up -d

# Stop running containers
docker-compose stop

# Remove running containers
docker-compose rm

Jenkins JVM Tuning

# Get PID of Jenkins
> docker exec jenkins-docker_jenkins_1 jcmd
7 /usr/share/jenkins/jenkins.war

# Dump Jenkins JVM properties
> docker exec jenkins-docker_jenkins_1 jcmd 7 VM.system_properties
> docker exec jenkins-docker_jenkins_1 jcmd 7 VM.flags

Project-based Matrix Authorization Strategy

Authenticated Users to be granted Overall-Read permissions to be able to login and view projects.

References

jenkins-docker's People

Contributors

deskoh avatar gscclive avatar bobbysy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.