Skip to content

Instantly share code, notes, and snippets.

@erselbey
Forked from Gogetter/jenkins-docker-compose.yml
Created August 25, 2021 10:54
Show Gist options
  • Save erselbey/60c05d6af3d172e6b75ddf85e9b3bc97 to your computer and use it in GitHub Desktop.
Save erselbey/60c05d6af3d172e6b75ddf85e9b3bc97 to your computer and use it in GitHub Desktop.
Jenkins container installation
version: "3.8"
services:
jenkins-docker:
image: docker:dind
restart: always
privileged: "true"
environment:
- DOCKER_TLS_CERTDIR=/certs
ports:
- "2376:2376"
networks:
jenkins:
aliases:
- docker
volumes:
- type: volume
source: jenkins-docker-certs
target: /certs/client
- type: volume
source: jenkins-data
target: /var/jenkins_home
jenkins-blueocean:
image: jenkinsci/blueocean
restart: always
environment:
- DOCKER_HOST=tcp://docker:2376
- DOCKER_CERT_PATH=/certs/client
- DOCKER_TLS_VERIFY=1
ports:
- "8080:8080"
- "50000:50000"
networks:
- jenkins
depends_on:
- jenkins-docker
volumes:
- type: volume
source: jenkins-data
target: /var/jenkins_home
- type: volume
source: jenkins-docker-certs
target: /certs/client
read_only: "true"
networks:
jenkins:
volumes:
jenkins-docker-certs:
jenkins-data:

This gist is based off of the Jenkins Docker setup

  • Create a bridge network in Docker.
docker network create jenkins 
  • Create volumes to share the Docker client TLS certificates needed to connect to the Docker deamon and persist the Jenkins data
docker volume create jenkins-docker-certs && docker volume create jenkins-data
  • In order to execute Docker commands inside Jenkins nodes, download and run the docker:dind Docker image

    Option A. Run below command, to delete container automatically once stopped for any reason. Prefer this if you want containers to tidy up after themselves

docker container run --name jenkins-docker --rm --detach --privileged --network jenkins --network-alias docker --env DOCKER_TLS_CERTDIR=/certs --volume jenkins-docker-certs:/certs/client --volume jenkins-data:/var/jenkins_home --publish 2376:2376 docker:dind

Option B. Run this command to always restart container once stopped. Prefer this option if you want this long term

docker container run --name jenkins-docker --restart always --detach --privileged --network jenkins --network-alias docker --env DOCKER_TLS_CERTDIR=/certs --volume jenkins-docker-certs:/certs/client --volume jenkins-data:/var/jenkins_home --publish 2376:2376 docker:dind
  • Now, download the jenkinsci/blueocean image and run it as a container in Docker.

    Option A. Run below command, to delete the container automatically once stopped for any reason. Prefer this if you want containers to tidy up after themselves

    docker container run --name jenkins-blueocean --rm --detach --network jenkins --env DOCKER_HOST=tcp://docker:2376 --env   DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 --publish 8080:8080 --publish 50000:50000 --volume jenkins-  data:/var/jenkins_home --volume jenks-docker-certs:/certs/client:ro jenkinsci/blueocean
    

    Option B. Run this command to always restart container once stopped. Prefer this option if you want this long term

    docker container run --name jenkins-blueocean --restart always --detach --network jenkins --env     DOCKER_HOST=tcp://docker:2376 --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 --publish 8080:8080 --publish  50000:50000 --volume jenkins-data:/var/jenkins_home --volume jenks-docker-certs:/certs/client:ro jenkinsci/blueocean
    
  • Navigate to localhost:8080 from your browser and you should see a similar screen as below.

    jenkins_initial_setup_page
  • Now get the password by running the below command. Copy and paste in Administrator password text box from above screen

    docker container logs jenkins-blueocean
    
    jenkins_container_logs_for_password
  • No click on Continue

  • Since we are doing a basic setup, click Install suggested plugins. Once clicked you should see below screen

    Installing suggested Jenkins plugins
  • On the next screen, create an Admin User

  • Follow rest of default installation pages.

  • Once completed you should see your newly created Jenkins Dashboard jenkins_is_ready

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