I installed Jenkins on Ubuntu. Added current user to docker group:
sudo usermod -aG docker ${USER}
Also added jenkins
user to docker group:
sudo usermod -aG docker jenkins
I set this shell command in a Jenkins job:
#!/bin/sh
docker-compose up -d --build
Got these console output from Jenkins after ran that job:
...
$ /bin/bash /tmp/jenkins1207165068215188667.sh
Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
But if I try the command docker-compose up -d --build
on the host under jenkins
user, it works. Why can't work use Jenkins' shell command?
And, why it let me to use docker-machine
? I tried to create a docker machine, but the default driver is virtualbox
. Since I am using Ubuntu without GUI, I think the virtualbox
is not necessary.
Did you set the DOCKER_HOST env var? That is more or less what docker-machine use ...
does. You need to tell docker what socket to connect to, and possibly there is some .bashrc or similar that runs when you log in under jenkins that sets that? Check DOCKER_HOST var before you run docker-compose up -d
as jenkins and see what the value is. Then you can export DOCKER_HOST=...
in your script when you know that.