0

I am getting below error while I am building docker image using Jenkins Pipeline. I have created Dockerfile in the GitHub.

Please find the below Jenkins File which I used.

Pipeline {

stage('build docker image') {

        steps {
            sh "pwd"
            sh "ls -l"

            sh "docker build -t dockerhub-image Dockerfile"

        }

}

}

Please find the below output as well.

pwd --> output

/var/lib/jenkins/workspace/pipeline

ls -l

rw-r--r- 1 jenkins jenkins 11 Nov 24 06:26 Dockerfile

rw-r--r- 1 jenkins jenkins 46 Nov 24 04:57 README.md

rw-r--r- 1 jenkins jenkins 5970 Nov 24 04:57 pom.xml

########### docker build -t dockerhub-image Dockerfile ####

ERROR:: unable to prepare context: context must be a directory: /var/lib/jenkins/workspace/pipeline/Dockerfile

Can you please help me on this, I tried several times but not working.

I have used below command's as well to build the image, but same issue.

docker build -t dockerhub-image Dockerfile

docker build -t dockerhub-image .

docker build -t dockerhub-image -f Dockerfile

I tried to search in old issues in stack overflow, but everyone saying that check the Dockerfile is present or not and check the Dockerfile naming convention, but everything is fine.

kaka
  • 1
  • 1
  • 1
  • 4
  • `docker build`'s argument is the _directory_ containing the Dockerfile, not the Dockerfile itself. `docker build .` (your middle option) is pretty common and I'd expect it to work. – David Maze Nov 24 '22 at 12:00
  • Hi @DavidMaze. I have tried middle one but getting permission denied error. docker build -t nginx-image . – kaka Nov 24 '22 at 14:20
  • Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=nginx-image&target=&ulimits=null&version=1": dial unix /var/run/docker.sock: connect: permission denied – kaka Nov 24 '22 at 14:20
  • Team, why my question is deleted, please check my comments if you find answer with my exact error and my comments. you can delete my account as well. – kaka Nov 24 '22 at 14:22
  • That "permission denied" error is covered in [How to fix docker: Got permission denied issue](https://stackoverflow.com/questions/48957195/how-to-fix-docker-got-permission-denied-issue). – David Maze Nov 24 '22 at 16:27

0 Answers0