There was the exact word that I used in a Google search recently, and it was challenging to find the correct answer. In the end, I didn't find it. So, I'm writing my solution to help others with that familiar doubt. First, we must install Jenkins Docker; you can discover how in the official documentation here.

But, if you only follow the documentation, you can run Jenkins to build standard pipelines and almost all kinds of projects. However, if you try to run a "Dockerized" project, you'll receive a permission access error.

To resolve this problem, I had to create a custom Jenkins image and install a Docker client together in this image, as you can see in the Dockerfile below.

FROM jenkins/jenkins:lts

# Switch the user to root to install the docker CLI
USER root
# Install docker CLI inside the container
RUN curl -sSL https://get.docker.com/ | sh
# Add Jenkins user to docker group (run without sudo)
RUN usermod -aG docker jenkins
# Switch back user to Jenkins
USER jenkins

Now, just run:

docker build -t my-custom-jenkins .
docker run -it -t -p 8080:8080 \
       --volume jenkins-data:/var/jenkins_home \
       --volume /var/run/docker.sock:/var/run/docker.sock my-custom-jenkins

After that, you can build and run a Docker container with Jenkins running inside the Docker container. This simple blog post helps you as it helps me. Thank you. See you.