Skip to content

Instantly share code, notes, and snippets.

@ismet55555
Last active December 7, 2020 15:34
Show Gist options
  • Save ismet55555/f614653a508d586888c746907f11245b to your computer and use it in GitHub Desktop.
Save ismet55555/f614653a508d586888c746907f11245b to your computer and use it in GitHub Desktop.
Jenkins Setup in Docker

Jenkins Setup Using Docker

  1. Install docker

  2. Install docker-compose

  3. Create the jenkins home directory docker for bind mounted volume

    • mkdir ~/jenkins
  4. Create docker-compose.yml

version: '3.8'
services:
  jenkins:
  image: jenkinsci/blueocean
  privileged: true
    user: root
    ports:
      - 8081:8080
      - 50000:50000
    container_name: jenkins
    volumes:
      - ~/jenkins:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/local/bin/docker:/usr/local/bin/docker
  1. Run the docker-compose.yml file

    • docker-compose up -d
  2. Get the initial setup admin password for jenkins setup

    • docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
  3. Using web-browser navigate to localhost:8081 to finish the setup


Note On Volume Mounts

  • As stated here, named volume mounts, are easuer to back up and migrate. In order to use named volume mounts instead of bind mounts, use the following docker-compose.yml
version: '3.8'
services:
  jenkins:
    image: jenkinsci/blueocean
    privileged: true
    user: root
    ports:
      - 8081:8080
      - 50000:50000
    container_name: jenkins
    volumes:
      - jenkins-home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/local/bin/docker:/usr/local/bin/docker
volumes:
  jenkins-home:

Note On AWS EC2 Installation

  • Install docker using these steps:

  • Remember to expose/add Security Group Inbound Rule

    • Public Access: TCP, Port 8081, from 0.0.0.0/0
    • Custom Access: TCP, Port 8081, form YOUR PUBLIC IP ADDRESS CIDR RANGE
  • If you configure scuirty group inbound rule to be public, make sure to change the default admin password! If you don't people obviously will know the default jenkins admin password ...

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