第一种情况 gitlab-runner用户执行 docker-compose 命令时异常
[gitlab-runner@k8s-master ~]$ docker-compose build
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.
[gitlab-runner@k8s-master ~]$
原因是gitlab-runner用户没有执行docker命令的权限,解决办法是将gitlab-runner用户加入到docker用户组
[gitlab-runner@k8s-master ~]$ sudo gpasswd -a ${USER} docker
正在将用户“gitlab-runner”加入到“docker”组中
[gitlab-runner@k8s-master ~]$
# 重新连接终端
第二种情况 执行 docker 命令没有权限
[gitlab-runner@k8s-master ~]$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/images/json: dial unix /var/run/docker.sock: connect: permission denied
[gitlab-runner@k8s-master ~]$ sudo gpasswd -a ${USER} docker
[sudo] gitlab-runner 的密码:
gitlab-runner 不在 sudoers 文件中。此事将被报告。
[gitlab-runner@k8s-master ~]$
# 切换到 root用户
[gitlab-runner@k8s-master ~]$ su
[gitlab-runner@k8s-master ~]$ visudo
# 加入gitlab-runner用户才可以给用户授权
gitlab-runner ALL=(ALL) NOPASSWD: ALL

发表评论

电子邮件地址不会被公开。 必填项已用*标注