Skip to content

Instantly share code, notes, and snippets.

@liejuntao001
Created January 21, 2020 22:38
Show Gist options
  • Save liejuntao001/380e5fe1bda2daf4c8505bc429772aa6 to your computer and use it in GitHub Desktop.
Save liejuntao001/380e5fe1bda2daf4c8505bc429772aa6 to your computer and use it in GitHub Desktop.
// Reference https://github.com/jenkinsci/kubernetes-plugin/blob/master/examples/dind.groovy
/*
“Docker-in-Docker”: runs a Docker-based build where the Docker daemon and client are both defined in the pod.
This allows you to control the exact version of Docker used.
(For example, try DOCKER_BUILDKIT=1 to access advanced Dockerfile syntaxes.)
There is no interaction with the container system used by Kubernetes:
docker.sock does not need to be mounted as in dood.groovy.
May or may not work depending on cluster policy: https://kubernetes.io/docs/concepts/policy/pod-security-policy/
*/
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:19.03.1
command:
- sleep
args:
- 99d
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: docker-daemon
image: docker:19.03.1-dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
''') {
node(POD_LABEL) {
git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
container('docker') {
sh 'docker version && DOCKER_BUILDKIT=1 docker build --progress plain -t testing .'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment