Giter Site home page Giter Site logo

jenkins-docker's Introduction

jenkins-docker (Windows)

Read before

ALWAYS START FROM OFFICIAL DOCUMENTATION!!! - click it It's strongly said to run Jenkins in Docker on Windows!!! Don't even try run Jenkins on Windows directly!!! Well you can, for simple tasks, but don't expect that everything will work (like Jenkinsfile, dockers). For it use Jenkins on Docker.

Using Simple Docker for Jenkins with Docker inside

Project contains instruction how to setup simple Docker container with Jenkins with Docker inside. It also contains simple Jenkinsfile and Dockerfile just to verify that Dockerfile from official repository is still working - it should. And it also shows how you can use Dockerfile(s) created for application in Jenkinsfile (this Dockerfile can contains instruction defining installation instruction for your application). Jenkinsfile run build of this Dockerfile.

About

I was planning to run many applications like python scripts, java applications and other in Docker on Jenkins using Jenkinsfiles to automate testing and preventing regression (e.g. block merge when build fail). I did not expect that I face so many issued only because I decided to run Jenkins on Windows instead Linux.

The last problem overflowing bitterness was problem with using Dockers in Jenkins.

As a first solution I found jenkins-withdocker docker image, it was good, but it was still not perfect. E.g. It didn't contain Blue Ocean, I was not sure that Image will be update all the time when new Jenkins is released. This Docker images may be not up to date when you use global Docker repository (it have to be rebuild every time when Jenkins releases new version).

Reason

I created this repository to be able setup docker in the future with simple steps described in this README.

Why Jenkins on Windows in Docker?

Jenkins on Windows have problems with:

I spent too much time on solving other integration problems between windows, wsl and docker, configuration, etc. I decided to move Jenkins to linux using Dockers and it was a good choice.

Solution

The best solution turned out to be using the Docker image with Jenkins with Docker inside as it is suggested in the official Jenkins documentation, so don't event try run Jenkins on Windows without Docker! Well you can use it without Docker, but only for a simple tasks.

Therefore, as the final solution I create this README to guide you how to setup easily working Jenkins on Windows.

Used docker image freshness

From Jenkins documentation: "A new jenkinsci/blueocean image is published each time a new release of Blue Ocean is published." (link)

Installation

Docker on Windows

Requirements (Docker requirements):

Instruction and detail:

Install Docker Desktop for Windows

In short steps:

  1. Download docker installer Docker Desktop Installer.exe
  2. Follow the install wizard
  3. Click Finish
  4. Run application and login

CPU Virtualization

In order to run docker CPU Virtualization must be enabled. You can enable it in the BIOS. Check if virtualization is enabled

Build docker image and run

  • create any directory for Jenkins files (Jenkins in Docker will be installed outside docker image and will be mounted - to be able recreate environment without losing jenkins configuration, jobs, workspace, installed additional plugins, etc.)
  • use command line and execute instruction below
docker run ^
  -u root ^
  --rm ^
  -d ^
  -p 8080:8080 ^
  -p 50000:50000 ^
  -v "E:/Docker/Jenkins":/var/jenkins_home ^
  -v /var/run/docker.sock:/var/run/docker.sock ^
  --name jenkins ^
  jenkinsci/blueocean

Where:

  • -u root - is needed to be able bind docker service with jenkins
  • -d - run as daemon, so you can detach console window
  • -p 8080:8080 and -p 50000:50000 - expose jenkins ports for main Jenkins and slave communication
  • E:/Docker/Jenkins - my created directory
  • -v /var/run/docker.sock:/var/run/docker.sock - mount/bid docker sockets
  • --name jenkins - alias for created container - e.g. to be able login docker machine easily
  • jenkinsci/blueocean - name of docker used to create Jenkins - released every time when new blue ocean is released

More details on the official Jenkins documentation

Running created container

$ docker container start jenkins

Removing container and image

Listing running container
$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
42e3edd6087b        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   12 minutes ago      Up 12 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins
Listing all container
$ docker container ls --all
Stop container
$ docker container stop jenkins

Note: You can use Container ID instead alias name

Remove container
$ docker container rm jenkins

Note: Stopping and removing container is also required to be able rebuild docker (container)

Remove image
$ docker image rm jenkinsci/blueocean
Bulk removing images and containers:
Windows:
@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker rm %%i
FOR /f "tokens=*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi %%i
Linux
#!/bin/bash
# Delete all containers
$ docker rm $(docker ps -a -q)
# Delete all images
$ docker rmi $(docker images -q)

Or short (on windows as well):

$ docker system prune

Jenkins configuration

Open web browser and type address localhost:8080 and follow instruction: Unlocking Jenkins.

The /var/jenkins_home/secrets/initialAdminPassword file is located under mounted place. e.g. in my case it is E:/Docker/Jenkins/secrets/initialAdminPassword (/var/jenkins_home is "mapped" to E:/Docker/Jenkins)

I suggest install without any plugins (select None) and add it later.

And that's it. You can open web browser, typ http://localhost:8080 and start using jenkins with docker.
E.g. Open Blue ocean view, create new pipeline, use e.g. github, add token, project and that's it. You can run Jenkinsfile pipeline with dockers.

Note

I just create it as the instruction.

Source

jenkins-docker's People

Contributors

auriuki avatar

Watchers

 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.