Skip to content

Instantly share code, notes, and snippets.

@ghsatpute
Created February 11, 2021 13:24
Show Gist options
  • Save ghsatpute/f0c36cdb4078a4a2a3ef0371a6987957 to your computer and use it in GitHub Desktop.
Save ghsatpute/f0c36cdb4078a4a2a3ef0371a6987957 to your computer and use it in GitHub Desktop.
How to run Docker commands inside a container ran by Jenkins Pipeline

How to run Docker commands inside a container ran by Jenkins Pipeline

First, in your base image install Docker

FROM ubuntu:latest
... 

RUN apt-get update \
     && apt-get install -y docker.io \
... 

When running the pipeline tell Jenkins to mount Docker socket inside Docker container by adding below command

pipeline {

    agent {
        docker {
            image '<previously built docker image>'
            args '-v /var/run/docker.sock:/var/run/docker.sock'     # <--- This line 
        }
    }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment