Mkdir /.docker: permission denied error when trying to build docker image from Jenkins pipeline on Mac

Hi, I’m running Jenkins for MacOS (using Homebrew) and Docker Desktop on Mac.
When I try to build docker image for Python app from Jenkins pipeline, the following error is reported:

+ docker build -t <docker image name> .
ERROR: mkdir /.docker: permission denied

Jenkinsfile snippet:

pipeline {
    agent none
    stages {
        ...
            stage("Build Docker Image") {
            agent {
                docker { image 'docker:24.0.5' }
            }
            steps {
               script {
                dockerImage = docker.build("<docker image name>:${env.BUILD_ID}")
               }
            }
        }
        ...
    }
}

Dockerfile (from root path on GitHub repository):

FROM python:alpine3.18
WORKDIR /app
COPY requirements.txt /app
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . /app
CMD ["flask", "run","--host","0.0.0.0","--port","5000"]

In previous stages, docker containers are successfully used.
EDIT:
I needed to apply this workaround: How to Setup Docker in Jenkins on Mac - Harshit Yadav - Medium because I have faced docker command not found issue before this one.
I assume that the user for Jenkins does not have permissions to write in ./docker dir but I’m not sure which user this is.
Every help is welcome. Thank you in advance for your time.

it’s trying to create .docker on the root of the filesystem /.

should it be using ./.docker instead of /.docker?

Hi @krachynski , thank you a lot for your fast response! :slight_smile:
Good idea, do you know maybe how to change/configure this? Thanks!

Honestly, I’m not sure. I’ve never known docker itself to try and create a directory at root.

I solved reported issue by setting HOME to ${env.WORKSPACE} inside mentioned Jenkins stage:

environment {
                HOME = "${env.WORKSPACE}"
            }

I hope it helps someone.

1 Like