Jenkins Pipeline Docker Agents with official Jenkins Docker image I'm using the official jenkins:lts image to host a Jenkins instance, with the Docker control socket forwarded inside the container to allow Jenkins to start new containers, and now I'm trying to run a pipeline that starts with

pipeline {
    agent {
        docker {
            image 'toolchain:2011'
            args '-v ${WORKSPACE}:${WORKSPACE} -w ${WORKSPACE}'
…


Running this job tries to execute the docker command inside the Jenkins container, which doesn't work because the package isn't installed. The regular Docker plugin works fine, as it uses the control socket directly instead of trying to run external programs.

I suspect I'm not the first person to do this -- how would I set up a Jenkins instance inside a container that can execute a pipeline with a "docker" agent?
You have to extend the jenkins/jenkins:lts to install the Docker client:

FROM jenkins/jenkins:lts

# Switch to root
USER root

ENV DOCKER_VERSION      docker-18.06.3-ce
ARG DOCKER_GID=993 # put the correct docker gid

# Download and install docker client
RUN wget --quiet -O- \
  https://download.docker.com/linux/static/stable/x86_64/${DOCKER_VERSION}.tgz | \
  tar zx --strip-components=1 -C /usr/local/bin docker/docker \
  &amp;&amp; groupadd -g ${DOCKER_GID} docker \
  &amp;&amp; usermod -aG docker jenkins

# Switch back to jenkins user
USER jenkins


You can now declare pipelines with docker agents.