Running Jenkins inside a container is a common setup.
This article shows you how to set up Jenkins to run in a container so that it can build and scan Docker images.
Setting up and starting a Jenkins container
To set up Jenkins to run in a container:
Prerequisite:
You have already installed Docker on the host machine.
Create the following Dockerfile. It uses the base Jenkins image and sets up the required permissions for the jenkins user.
FROM jenkins/jenkins:lts
USER root
RUN apt-get update \
&& apt-get install -y sudo libltdl7 \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
Build the image.
$ docker build -t jenkins_docker .
Run the Jenkins container, giving it access to the docker socket.