Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins pipeline : docker not found [duplicate]

i wanted to create a docker image with jenkins but docker not found

how can i add jenkins to docker groupe on windows ? i tried to add docker plugin and didn't work

this is my pipeline

pipeline {
    agent any
    options { buildDiscarder(logRotator(numToKeepStr:'5'))}
    environment {DOCKERHUB_CREDENTIALS = credentials('tfkben-dockerhub')}
    stages {
            stage('build'){  steps {  sh 'docker build -t tfkben/ben:latest .' }  }
            stage('Login'){  steps {  sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin ' }}
            stage('Push'){  steps {  sh 'docker push tfkben/ben:latest'}   }                                 
         }                           
            post { always { sh 'docker logout' }}
}

my Dockerfile :

FROM python:3.11-rc-bullseye

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "python3", "manage.py", "runserver", "0.0.0.0:8000"]

and this is the error message :

  • docker build -t tfkben/ben:latest . /var/jenkins_home/workspace/dockerhub-auth_master@tmp/durable-d7adec4b/script.sh: 1: docker: not found
like image 457
Toufik Benkhelifa Avatar asked Oct 16 '25 00:10

Toufik Benkhelifa


1 Answers

If you try to run Jenkins inside a container instead :

docker run -u 0 --privileged --name jenkins -d -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

Of course you could replace $(which docker) directly by your docker path if your host machine doesn't recognize the command.

You should be able to run docker command inside your pipeline.

like image 155
Joffrey K Avatar answered Oct 18 '25 14:10

Joffrey K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!