![](/img/trans.png)
[英]Jenkins/ MacOS - dial unix /var/run/docker.sock: connect:permission denied
[英]Jenkins dial unix /var/run/docker.sock: connect: permission denied MacOS
我在本地運行Jenkins,並且在我的計算機上也安裝了docker。
我有一個使用Jenkins文件的Jenkins工作
我在Jenkins中安裝了所有docker插件,但是當執行Build步驟時,我得到了...
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Post
http://%2Fvar%2Frun%2Fdocker.sock/v1.39/build?
buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=w6ypm3t1b0qefyxh9omfvntru&shmsize=0&t=app-web&target=&ulimits=null&version=1: dial unix /var/run/docker.sock: connect: permission denied
我似乎無法更改以下用戶的權限
lrwxr-xr-x 1 macuser staff 72 Jun 30 20:36 docker.sock -> /Users/john/Library/Containers/com.docker.docker/Data/docker.sock
任何幫助,不勝感激
您的主要問題是因為通過Jenkins使用的用戶(可能名為jenkins
沒有足夠的權限來運行jenkins
。
因此,您基本上需要使用戶加入staff
組。
我幾天前已經回答了這個問題,答案的后半部分是您要尋找的: 如何從Mac OS X命令行將用戶添加到組中?
請進行測試,並在嘗試將用戶添加到staff
組時獲得的輸出讓我知道它是否不適合您
使用Mac的Docker,在容器內您會發現Docker套接字歸root所有(這是嵌入式LinuxKit VM的一部分)。 我在Jenkins容器內使用以下入口點,並以root用戶身份運行入口點,以自動重新配置容器內的docker組以匹配套接字文件的組ID,然后在運行Jenkins之前從root放到jenkins用戶應用程序本身。 這樣做的優點是可移植,可以在任何桌面或服務器環境上運行,而無需將Docker GID硬編碼到容器中:
#!/bin/sh
# By: Brandon Mitchell <public@bmitch.net>
# License: MIT
# Source Repo: https://github.com/sudo-bmitch/jenkins-docker
set -x
# configure script to call original entrypoint
set -- tini -- /usr/local/bin/jenkins.sh "$@"
# In Prod, this may be configured with a GID already matching the container
# allowing the container to be run directly as Jenkins. In Dev, or on unknown
# environments, run the container as root to automatically correct docker
# group in container to match the docker.sock GID mounted from the host.
if [ "$(id -u)" = "0" ]; then
# get gid of docker socket file
SOCK_DOCKER_GID=`ls -ng /var/run/docker.sock | cut -f3 -d' '`
# get group of docker inside container
CUR_DOCKER_GID=`getent group docker | cut -f3 -d: || true`
# if they don't match, adjust
if [ ! -z "$SOCK_DOCKER_GID" -a "$SOCK_DOCKER_GID" != "$CUR_DOCKER_GID" ]; then
groupmod -g ${SOCK_DOCKER_GID} -o docker
fi
if ! groups jenkins | grep -q docker; then
usermod -aG docker jenkins
fi
# Add call to gosu to drop from root user to jenkins user
# when running original entrypoint
set -- gosu jenkins "$@"
fi
# replace the current pid 1 with original entrypoint
exec "$@"
您可以在以下位置找到完整的示例,包括用於在映像內安裝docker和gosu的Dockerfile: https : //github.com/sudo-bmitch/jenkins-docker
相同的概念存在於我的基礎映像中的fix-perms
腳本中,該腳本可以應用於其他場景: https : //github.com/sudo-bmitch/docker-base
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.