docker - 在 Jenkins 构建中运行 docker 脚本时出现编译错误
问题描述
我一直在阅读 docker book,现在正在学习 CI。我试图在我的构建的执行 shell 中运行这个脚本:
# Build the image to be used for this job.
IMAGE=$(sudo docker build . | tail -1 | awk '{ print $NF }')
# Build the directory to be mounted into Docker.
MNT="$WORKSPACE/.."
# Execute the build inside Docker.
CONTAINER=$(sudo docker run -d -v $MNT:/opt/project/ $IMAGE /bin/ bash -c 'cd /opt/project/workspace; rake spec')
# Attach to the container so that we can see the output.
sudo docker attach $CONTAINER
# Get its exit code as soon as the container stops.
RC=$(sudo docker wait $CONTAINER)
# Delete the container we've just used.
sudo docker rm $CONTAINER
# Exit with the same value as that with which the process exited.
exit $RC
运行此脚本以构建失败告终。它显示了这两个错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
和
sudo docker run -d -v /private/var/jenkins_home/jobs/${Docker_test_job}/workspace/..:/opt/project/ /bin/ bash -c cd /opt/project/workspace; rake spec
docker: invalid reference format.
See 'docker run --help'.
+ CONTAINER=
Build step 'Execute shell' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
我不明白如何修复它,因为我一直按照书中的说明进行操作。我尝试使用 $PWD 来尝试解决我的问题,但这也不起作用。
解决方案
实际上 jenkins 用户没有运行 docker 命令的权限。为此,请将您的 jenkins 用户添加到 docker 组:
sudo usermod -aG docker jenkins
然后重新启动您的 jenkins 服务器以刷新组。请注意,有一条警告“docker 组授予与 root 用户等效的权限。有关这如何影响系统安全性的详细信息。”
推荐阅读
- ios - Cordova GET 请求在 IOS 上丢失服务器端 cookie
- c# - C# shell.NameSpace 在外部设备上找不到文件夹
- azure - 在 Azure Web 服务中发送电子邮件超时
- excel - 使用 Range.Address 时 VBA 中图表集源数据的运行时错误
- c# - 超过 3MB 的字节 [] 在 API C# 中出现 NULL
- swift - SwiftUI - 向自定义结构添加滑动操作不会显示在模拟器中
- python - 有比这个嵌套循环更好的原因吗?
- javascript - 如何将 display none 转换为 flex?
- plotly - 绘图地图不显示几何图形
- discord-jda - 回复在 JDA 中向您发送他的第一个 DM 的人