Executing docker commands in Jenkins Pipeline

Hello, I am following the course Jenkins Project: Building CI/CD Pipeline for Scalable Web Applications. I am trying to execute a pipeline (in my hos, on my jenkins server which is debian based) that builds a docker image based on the code, but it always fails with error: Sorry, home directories outside of /home needs configuration.
i installed docker and docker pipeline plugins, i used agent any ad even
agent {
docker{
image ‘docker:latest’
args ‘-v /var/run/docker.sock:/var/run/docker.sock’
}
}
could anyone help me with this matter?
Capture d'écran 2025-05-07 222542

It looks like you’ve installed Jenkins using snap. This can be handy, but it comes with restrictions that snap places on the processes it manages. You can work around these limitations, but it’s a pain, and you’re seeing an example of it here.

You may want to reinstall Jenkins using the instructions from the Jenkins install page. This will prevent issues like the one you’re seeing.

1 Like

Hi @hiba06

Make sure the jenkins user can run Docker:

sudo usermod -aG docker jenkins
sudo systemctl restart jenkins

An easier way is to run Jenkins in Docker and mount the Docker socket:

docker run -d \
  --name jenkins \
  -p 8080:8080 -p 50000:50000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ~/jenkins_home:/var/jenkins_home \
  jenkins/jenkins:lts

This allows Jenkins to use Docker CLI directly. As your project grows, you can move this setup to Docker Compose, Swarm, or Kubernetes for better scalability.

1 Like

Thank you for your help! Problem solved when running Jenkins in Docker but actually, I had also to install docker inside the container. So i had to create a dockefile to do that.
Finally I followed the installation from this website: Docker