Skip to content

Instantly share code, notes, and snippets.

@adelmofilho
Created June 21, 2020 00:17
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save adelmofilho/5a30a87eaf1cd4a03052f37b516d6714 to your computer and use it in GitHub Desktop.
Save adelmofilho/5a30a87eaf1cd4a03052f37b516d6714 to your computer and use it in GitHub Desktop.
Docker-in-Docker approach to run Jenkins as a Docker container
# This docker-compose file intent to create a multi-container application
# that runs a Jenkins container connected via TLS to a Docker-in-Docker (dind) container as Docker daemon.
#
# Advice about this approach can be found at:
# http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/
#
# As well discussion about another alternatives on this setup can be found at:
# https://forums.docker.com/t/using-docker-in-a-dockerized-jenkins-container/322/11
#
# Quick reference about Docker-in-Docker can be fount at:
# https://hub.docker.com/_/docker
#
# Main source: https://www.jenkins.io/doc/tutorials/create-a-pipeline-in-blue-ocean/
version: '3.1'
networks:
docker:
volumes:
jenkins-data:
jenkins-docker-certs:
services:
jenkins:
image: jenkinsci/blueocean
restart: always
networks:
- docker
ports:
- 8080:8080
- 50000:50000
tty: true
volumes:
- jenkins-data:/var/jenkins_home
- jenkins-docker-certs:/certs/client:ro
- $HOME:/home
environment:
- DOCKER_HOST=tcp://docker:2376
- DOCKER_CERT_PATH=/certs/client
- DOCKER_TLS_VERIFY=1
dind:
image: docker:dind
privileged: true
restart: always
networks:
docker:
aliases:
- docker
ports:
- 2376:2376
tty: true
volumes:
- jenkins-data:/var/jenkins_home
- jenkins-docker-certs:/certs/client
- $HOME:/home
environment:
- DOCKER_TLS_CERTDIR=/certs
@nitish-predera
Copy link

That worked well. Thank you!

Copy link

ghost commented Sep 16, 2020

ty, my dier friend, for this file!

@abdennour
Copy link

give also volume for docker storage

 dind:
   # ...
    volumes:
      - docker-graph-storage:/var/lib/docker
    
volumes:
  # ...
  docker-graph-storage:

Enjoy as well

@SalHe
Copy link

SalHe commented May 8, 2021

Thank you guy, it works well on my machine.

@varxnnn
Copy link

varxnnn commented Apr 25, 2023

@abdennour what is that volume used for?

@NgocHungWeploy
Copy link

Thank you guy. It work well on My Machine. Mac Pro Silicon chip M2. 13.3.1 (22E261)

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