使用teamcity-docker-agent时运行docker - 权限被拒绝

时间:2017-10-18 06:31:23

标签: docker teamcity

我们在本地TeamCity服务器上使用2017.1.5(build 47175),并使用最新的teamcity-docker-agent for ubuntu。

启动teamcity-docker-agent时,我们添加:

-v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker

使docker在容器内可用。

当运行在docker容器中执行的示例gradle构建时,它无法运行/opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.shdue来解决权限问题。

是否有人在teamcity-docker-agent中使用docker而没有这些问题?

root@99decd9a0703:/# ll /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh

-rw-r--r-- 1 root root 225 Oct 18 06:08 /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh

构建日志:

[06:08:17][Step 1/1] Starting: /bin/sh -c docker pull openjdk && docker run --rm -w /opt/buildagent/work/472d663c385d6aef -v /opt/buildagent/work/472d663c385d6aef:/opt/buildagent/work/472d663c385d6aef -v /opt/buildagent/temp/agentTmp:/opt/buildagent/temp/agentTmp -v /opt/buildagent/temp/buildTmp:/opt/buildagent/temp/buildTmp -v /opt/buildagent/system:/opt/buildagent/system -v /opt/buildagent/lib:/opt/buildagent/lib:ro -v /opt/buildagent/tools:/opt/buildagent/tools:ro -v /opt/buildagent/plugins:/opt/buildagent/plugins:ro --env-file /opt/buildagent/temp/agentTmp/docker-wrapper-3086677386325386164.env --entrypoint /bin/sh openjdk /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
[06:08:17][Step 1/1] in directory: /opt/buildagent/work/472d663c385d6aef
[06:08:17][Step 1/1] Using default tag: latest
[06:08:19][Step 1/1] latest: Pulling from library/openjdk
[06:08:19][Step 1/1] Digest: sha256:9745ed74401b23fb845b4eb7ae07ecb7dc2d40bece6bdb089975a20f76766401
[06:08:19][Step 1/1] Status: Image is up to date for openjdk:latest
[06:08:20][Step 1/1] /bin/sh: 0: Can't open /opt/buildagent/temp/agentTmp/docker-shell-script-3687474573035166736.sh
[06:08:20][Step 1/1] Process exited with code 127
[06:08:20][Step 1/1] Process exited with code 127
[06:08:20][Step 1/1] Step Gradle failed

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题。这是目前(2017年3月)为我工作的。

<brackets>中的项目应替换为您的相关信息,并且实际上不应在您的终端请求中包含括号。 (即将AGENT_NAME="<your-new-tcagent-container-name>"替换为AGENT_NAME="my-agent-container"

为了便于阅读,我添加了换行符。您应该在粘贴到终端之前删除换行符。

您还需要确保在Docker中的Docker文件共享中列出了这些目录&gt;偏好&gt;文件共享: /Users/Volumes/private/tmp

docker run -it --name <your-new-tcAgent-CONTAINER-name>
-e SERVER_URL="<your-local-tcServer-CONTAINER-name>:8111" 
-e AGENT_NAME="<your-new-tcAgent-name-to-appear-in-tcserver>" 
-v /var/run/docker.sock:/var/run/docker.sock 
-v /opt/buildagent/work:/opt/buildagent/work 
-v /opt/buildagent/temp:/opt/buildagent/temp 
-v </where/you/wanna/store/local/configs>:/data/teamcity_agent/conf 
--link <your-local-tcServer-container-name>
<name-of-tcAgent-IMAGE-you-are-using>