I have been breaking my head over this problem the past few hours. My setup is as follows:
- Running Ubuntu 19.10 hosting docker
Running this docker-compose.yml file:
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
The host has the group docker with id 998. My Dockerfile for the jenkins container is as follows:
USER root
ARG DOCKER_GID=998
RUN groupadd -g ${DOCKER_GID} docker
RUN usermod -aG docker jenkins
However, when I try to build something in a Jenkins job, the following error pops up:
/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
The build stage is:
steps {
script {
docker.withRegistry('localhost:5000') {
def image = docker.build("url-shortener-backend:${env.BUILD_ID}")
image.push()
}
}
}
Can anyone spot what is going wrong here? Thanks in advance :)