Due to high Memory and CPU, I needed to spin up a new ec2 instance. After a while, tried to kick off my Jenkins CI/CD pipeline and got the following error: dial unix /var/run/docker.sock: connect: permission denied
. Let me share how I manage to fix it with you.
Prerequisites
- Jenkins
- sudo privileges
Solution
- I tried many of the other google solutions but none of them fixed the issue. So the fix was to add jenkins as an owner both (user and group), to the
docker.sock
inside the Jenkins container.sudo chown jenkins:jenkins /var/run/docker.sock
- Another option that might work but I didn’t give it a try, is to add the docker user (if exists inside the Jenkins container) as an owner to the
docker.sock
, and afterward put the jenkins user into the docker group.sudo chown docker:docker /var/run/docker.sock sudo usermod -aG docker jenkins
Conclusion
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.