0

I am using CloudBees Docker Custom Build Environment Plugin jenkins plugin to run my jobs inside container.

The problem is that I cannot build image. I am receiving this error:

Build Docker image from ./Dockerfile ...
$ docker build --file /Users/Shared/Jenkins/Home/workspace/Frontend/Dockerfile /Users/Shared/Jenkins/Home/workspace/Frontend
FATAL: Cannot run program "docker": error=2, No such file or directory

When I run which docker it returns /usr/local/bin/docker.

It seems that jenkins cannot access docker.

I am using MacOS X

Similar question: Jenkins build an image for Docker?

Joozty
  • 460
  • 2
  • 12
  • 40
  • Can you try `sudo chmod +x /usr/local/bin/docker` ? the problem is that the user jenkins does not have the privilege to run docker. – hichamx Apr 03 '18 at 14:39
  • @hichamx It didn't help. If there would be privilege problem then it wouldn't show directory not found error or am I wrong? – Joozty Apr 03 '18 at 14:43
  • the `which docker` command, did you run it as the user named "jenkins" created by jenkins? – hichamx Apr 03 '18 at 14:50
  • yes, both root and jenkins and it returns same path. – Joozty Apr 03 '18 at 14:53
  • 3
    can you try this command `sudo usermod -aG docker jenkins` and the run the jenkins job again – hichamx Apr 03 '18 at 14:56
  • I cannot run this command because I am using OS X. `sudo: usermod: command not found` – Joozty Apr 03 '18 at 14:57
  • 1
    I don't know about macOS but the idea is to add the user jenkins to the group docker, if there is no group called docker you have to create one. – hichamx Apr 03 '18 at 15:03
  • As an alternative to adding jenkins to the docker group, you can try to run the command as `sudo docker build ...` assuming jenkins user has sudo rights. However, be warned, jenkins has problems with sudo, at least on linux – Oleg Sklyar Apr 03 '18 at 15:08
  • By which user did you run Jenkins job? – Yuankun Apr 03 '18 at 15:09
  • @Yuankun Does it matter? Every jenkins build jobs is executing `jenkins` user, right? On my laptop I am logged as user with sudo privileges. – Joozty Apr 03 '18 at 15:12
  • @Joozty there is a comment in the following question, which seems to answer you question (the whole question remains unanswered, therefore not marking as duplicate): https://stackoverflow.com/questions/45391391/do-we-have-docker-group-on-mac And another hint here https://serverfault.com/questions/639459/why-might-the-jenkins-user-not-have-permission-to-access-the-docker-unix-socket/659043#659043 – Oleg Sklyar Apr 03 '18 at 15:26
  • Thank you @OlegSklyar but changing permission didn't solve my problem. – Joozty Apr 03 '18 at 15:34
  • You need understand if it is `docker` command itself causing the issue or arguments to it. Try setting up a basic jenkins job that doesn't run a custom build but instead deploys something from the hub, aka `docker run hello-world`. Then you will know if the problem is with docker or docker build – Oleg Sklyar Apr 03 '18 at 15:39
  • here is a workaround here https://github.com/docker/for-mac/issues/799 – hichamx Apr 03 '18 at 15:44
  • @hichamx Yes, that was first what I tried before I ask this question. Unfortunelly it didn't help. – Joozty Apr 04 '18 at 08:33
  • Any joy getting this resolved? – rogger2016 Jul 01 '19 at 19:19

0 Answers0