Skip to content

Instantly share code, notes, and snippets.

@Gogetter
Last active August 25, 2021 10:54
Show Gist options
  • Save Gogetter/4299f9a8b93471e0e601f99ac153e5cc to your computer and use it in GitHub Desktop.
Save Gogetter/4299f9a8b93471e0e601f99ac153e5cc 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
@Miguelme
Copy link

I am getting this error:

Client sent an HTTP request to an HTTPS server. when trying to run the test connection with docker on macOS. Do you have any idea what might be ?

@Gogetter
Copy link
Author

I am getting this error:

Client sent an HTTP request to an HTTPS server. when trying to run the test connection with docker on macOS. Do you have any idea what might be?

Hi, @Miguelme looks like a network issue. Please could you share the specific command you are trying to execute?

@Miguelme
Copy link

Thanks for your quick answer! I'm getting to the path: /configureClouds and then testing the tcp connection by setting it explicitly as follows:

tcp://docker:2376

@Gogetter
Copy link
Author

HI @Miguelme, so sorry for the very late response. Please could you help with more details and possible steps to reproduce this error?

@Wanderduene
Copy link

I have the same issue :/
Did you manage to solve it @Miguelme ?

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