我使用Jkube-maven插件在Ubuntu下的AWS EC2实例上通过Jenkins管道生成Docker镜像
当管道执行mvn clean install k8s:build
时,我收到以下错误:
[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.3.0:build (default-cli) on project social-carpooling-frontend: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.3.0:build failed: No <dockerHost> given, no DOCKER_HOST environment variable, no read/writable '/var/run/docker.sock' or '//./pipe/docker_engine' and no external provider like Docker machine configured -> [Help 1]
这是詹金斯管道:
pipeline {
agent any
stages {
stage('Docker Check Stage') {
steps {
sh '/home/bitnami/downloads/apache-maven-3.8.1/bin/mvn clean install k8s:build -Premote'
}
}
}
}
当我使用ssh登录到这台机器并执行docker -v
时,它会显示Docker version 20.10.0, build 7287ab3
所以Docker真的安装好了,守护进程也启动了,但当我通过maven触发它时,它似乎找不到它!有什么想法吗?
问题是由于运行maven命令的用户无法访问docker.sock
解决方案是这样修改docker.sock上的读/写权限:
sudo chmod 776 /var/run/docker.sock