Have a job in jenkins need to run docker-compose build
jenkins@CI:~/workspace/staging-backend$ docker-compose build
redis uses an image, skipping
elasticsearch uses an image, skipping
mysql uses an image, skipping
Building webapp
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
More details (confusing error logs)
jenkins@CI:~/workspace/staging-backend$ docker-compose --verbose build
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.find_config_file: Trying paths: ['/var/lib/jenkins/.docker/config.json', '/var/lib/jenkins/.dockercfg']
docker.auth.find_config_file: No config file found
Traceback (most recent call last):
File "bin/docker-compose", line 3, in <module>
File "compose/cli/main.py", line 68, in main
File "compose/cli/main.py", line 115, in perform_command
File "compose/cli/command.py", line 37, in project_from_options
File "compose/cli/command.py", line 99, in get_project
File "compose/cli/command.py", line 74, in get_client
File "site-packages/docker/api/daemon.py", line 177, in version
File "site-packages/docker/utils/decorators.py", line 46, in inner
File "site-packages/docker/api/client.py", line 189, in _get
File "site-packages/requests/sessions.py", line 488, in get
File "site-packages/requests/sessions.py", line 475, in request
File "site-packages/requests/sessions.py", line 596, in send
File "site-packages/requests/adapters.py", line 473, in send
requests.exceptions.ConnectionError: ('Connection aborted.', error(13, 'Permission denied'))
Failed to execute script docker-compose
Root cause & Solution:
User jenkins doesn't have permission to read/write docker unix socket
$ ls -l /var/run/docker.sock
srw-rw---- 1 root docker 0 Aug 14 09:21 /var/run/docker.sock
Switch to user ubuntu/root to add user jenkins to docker group
Try to run the following command to add to the group
$ sudo usermod -a -G docker jenkins
Run the following command to find out what groups you belong to
# groups $USER
$ groups ubuntu
ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd docker
Restart jenkins service, and logout-login jenkins to apply
Problem:
Have a job in jenkins need to run
docker-compose build
Root cause & Solution:
User
jenkins
doesn't have permission to read/write docker unix socketSwitch to user ubuntu/root to add user
jenkins
todocker
group Try to run the following command to add to the groupRun the following command to find out what groups you belong to
Restart jenkins service, and logout-login jenkins to apply
Export environment: