过去几个小时来,我一直在努力解决这个问题。我的设置如下:
运行此docker-compose.yml文件:
version: '3.7'
services:
jenkins:
command: --httpPort=80 --httpsPort=443 --httpsKeyStore=/var/jenkins_ssl/jenkins.jks --httpsKeyStorePassword=very-secret-password
build: .
privileged: true
user: root
ports:
- 80:8080
- 50000:50000
- 443:443
container_name: jenkins
volumes:
- ~/jenkins:/var/jenkins_home
- ~/jenkins-ssl:/var/jenkins_ssl
- ~/app_config/:/var/app_config/
- ~/app_logs/:/var/app_logs/
- /var/run/docker.sock:/var/run/docker.sock
- /usr/local/bin/docker:/usr/local/bin/docker
主机具有ID为998的组docker。我的jenkins容器的Dockerfile如下:
USER root
ARG DOCKER_GID=998
RUN groupadd -g ${DOCKER_GID} docker
RUN usermod -aG docker jenkins
但是,当我尝试在Jenkins作业中构建内容时,会弹出以下错误:
/var/jenkins_home/workspace/cicd-test-backend@tmp/durable-79b7d7d6/script.sh: 1: /var/jenkins_home/workspace/cicd-test-backend@tmp/durable-79b7d7d6/script.sh: docker: Permission denied
script returned exit code 127
构建阶段是:
steps {
script {
docker.withRegistry('localhost:5000') {
def image = docker.build("url-shortener-backend:${env.BUILD_ID}")
image.push()
}
}
}
有人能发现这里出了什么问题吗?在此先感谢:)