jenkinsci / docker

Docker official jenkins repo
https://hub.docker.com/r/jenkins/jenkins
MIT License
6.7k stars 4.54k forks source link

SSH docker not found. Jenkins #679

Closed BillioJeverson closed 3 years ago

BillioJeverson commented 6 years ago
pipeline {
    agent none
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'python:3.5.1'
                }
            }
            steps {
                sh 'python -m py_compile sources/add2vals.py sources/calc.py'
            }
        }
        stage('Test') {
            agent {
                docker {
                    image 'qnib/pytest'
                }
            }
            steps {
                sh 'py.test --verbose --junit-xml test-reports/results.xml sources/test_calc.py'
            }
            post {
                always {
                    junit 'test-reports/results.xml'
                }
            }
        }
        stage('Deliver') {
            agent {
                docker {
                    image 'cdrx/pyinstaller-linux:python2'
                }
            }
            steps {
                sh 'pyinstaller --onefile sources/add2vals.py'
            }
            post {
                success {
                    archiveArtifacts 'dist/add2vals'
                }
            }
        }
    }
}
#bellow is the error

[simple-python-yo] Running shell script
+ docker inspect -f . index.docker.io/python
/var/jenkins_home/workspace/simple-python-yo@tmp/durable-5fe0000e/script.sh: 2: /var/jenkins_home/workspace/simple-python-yo@tmp/durable-5fe0000e/script.sh: docker: not found
[Pipeline] sh
[simple-python-yo] Running shell script
+ docker pull index.docker.io/python
/var/jenkins_home/workspace/simple-python-yo@tmp/durable-95921c60/script.sh: 2: /var/jenkins_home/workspace/simple-python-yo@tmp/durable-95921c60/script.sh: docker: not found
andreacab commented 6 years ago

Did you find any solution? I am having the same problem.

BillioJeverson commented 6 years ago

apparently there is some bug in the new Jenkins pipelines plugin. so use this run in stead

docker run \ --rm \ -u root \ -p 8080:8080 \ -v jenkins-data:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock \ -v "$HOME":/home \ jenkinsci/blueocean

carlossg commented 6 years ago

@BillioJeverson running jenkins as root is a bad idea

You would have to check the logs but if running as root fixes the problem then it means you need to open up the /var/run/docker.sock permissions to allow the container user (1000) to access it

carlossg commented 6 years ago

I don't know what image are you using but in order to have run docker, the docker binary needs to be present in the image. There are turtorials on the net about running docker from a docker container

arcvpatel commented 6 years ago

I am running in to the same issue. Below is the error.

+ docker run -d docker pull evarga/jenkins-slave /home/jenkins/workspace/test-remote@tmp/durable-9ed959d1/script.sh: 2: /home/jenkins/workspace/test-remote@tmp/durable-9ed959d1/script.sh: docker: not found

The corresponding pipeline is following

` node {

withDockerServer([uri: 'tcp://54.221.134.252:2376']) {
    docker.image('docker pull evarga/jenkins-slave').withRun() {
        sh 'java -version'
    }
}

} `

Am I missing something? All I am trying to do is have Jenkins execute some task on a remote node that already has docker installed.

I have already tried the recommendation provided by @BillioJeverson but that didn't do anything.

Please help!

carlossg commented 6 years ago

in order to call docker from somewhere (master/agent) you need the docker cli installed there

arcvpatel commented 6 years ago

@carlossg , I do. When I SSH in to the docker container (the one that @BillioJeverson provided), I can execute following.

bash-4.4# docker -v and I get proper response. Docker version 17.12.1-ce, build 9584b2309e

ericuldall commented 6 years ago

I'm having a similar issue. I've mounted the host /usr/bin/docker and /var/run/docker.sock files in GKE When I exec into the pod/container I can run all docker commands as expected, but when I use docker from the Jenkinsfile I get docker: not found

The strange part is my output shows that the Docker bin file exists... SMH

[Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ] Running shell script
+ whoami
jenkins
[Pipeline] sh
[Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ] Running shell script
+ cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root,adm
lp:x:7:lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
floppy:x:11:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:man
cron:x:16:cron
console:x:17:
audio:x:18:
cdrom:x:19:
dialout:x:20:root
ftp:x:21:
sshd:x:22:
input:x:23:
at:x:25:at
tape:x:26:root
video:x:27:root
netdev:x:28:
readproc:x:30:
squid:x:31:squid
xfs:x:33:xfs
kvm:x:34:kvm
games:x:35:
shadow:x:42:
postgres:x:70:
cdrw:x:80:
usb:x:85:
vpopmail:x:89:
users:x:100:games
ntp:x:123:
nofiles:x:200:
smmsp:x:209:smmsp
locate:x:245:
abuild:x:300:
utmp:x:406:
ping:x:999:
nogroup:x:65533:
nobody:x:65534:
jenkins:x:10000:jenkins
[Pipeline] sh
[Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ] Running shell script
+ cat /etc/passwd
root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucppublic:/sbin/nologin
operator:x:11:0:operator:/root:/bin/sh
man:x:13:15:man:/usr/man:/sbin/nologin
postmaster:x:14:12:postmaster:/var/spool/mail:/sbin/nologin
cron:x:16:16:cron:/var/spool/cron:/sbin/nologin
ftp:x:21:21::/var/lib/ftp:/sbin/nologin
sshd:x:22:22:sshd:/dev/null:/sbin/nologin
at:x:25:25:at:/var/spool/cron/atjobs:/sbin/nologin
squid:x:31:31:Squid:/var/cache/squid:/sbin/nologin
xfs:x:33:33:X Font Server:/etc/X11/fs:/sbin/nologin
games:x:35:35:games:/usr/games:/sbin/nologin
postgres:x:70:70::/var/lib/postgresql:/bin/sh
cyrus:x:85:12::/usr/cyrus:/sbin/nologin
vpopmail:x:89:89::/var/vpopmail:/sbin/nologin
ntp:x:123:123:NTP:/var/empty:/sbin/nologin
smmsp:x:209:209:smmsp:/var/spool/mqueue:/sbin/nologin
guest:x:405:100:guest:/dev/null:/sbin/nologin
nobody:x:65534:65534:nobody:/:/sbin/nologin
jenkins:x:10000:10000:Linux User,,,:/home/jenkins:/sbin/halt
[Pipeline] sh
[Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ] Running shell script
+ which docker
+ ls -al /usr/bin/docker
-rwxr-xr-x    1 root     root      13824040 Aug 10 18:51 /usr/bin/docker
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] sh
[Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ] Running shell script
+ docker build -t test .
/home/jenkins/workspace/Jenkins_Test_master-X7ZXONKEVCID66HNGQM73UUVXH4FMW7SNZELILCSQFET2KKXXLYQ@tmp/durable-f120e817/script.sh: line 1: docker: not found

Any ideas on this?

marcosvrs commented 5 years ago

Same here.

pieterdt commented 4 years ago

here as well. I don't seem to have a docker binary in the jenkins/jenkins docker image. Should I add it manually?

gcoelho commented 4 years ago

@pieterdt I had to add docker binary manually. Indeed I wrote a new Dockerfile which extends the default jenkins/jenkins image copying docker binary, creating a docker group (975) and them adding the jenkins user (1000) to this new group.

If you prefer, instead of manually copying docker binary, you can install it using apt. In this case you don't need to manually create the docker group.

FROM jenkins/jenkins:latest

USER root
COPY docker /usr/bin/docker
RUN groupadd -g 975 docker && \
   usermod -aG docker jenkins

USER jenkins
sboris-git commented 4 years ago

Have got the same issue. Trying to fix in the way:

FROM jenkins/jenkins:latest

USER root COPY docker /usr/bin/docker RUN groupadd -g 975 docker && \ usermod -aG docker jenkins

USER jenkins

have got Step 3/5 : COPY docker /usr/bin/docker COPY failed: stat /var/lib/docker/tmp/docker-builder503410079/docker: no such file or directory $ which docker /usr/bin/docker Any suggestions?

gcoelho commented 4 years ago

@sboris-git Here I was copying to the container image a binary named docker which already exists on the same directory where you have the Dockerfile.

COPY docker /usr/bin/docker

In your case you dont had this binary. I had manually copied my local docker to the same folder where Dockerfile was before building the image. You can do the same and copy it or you can replace this COPY docker /usr/bin/docker by a apt install docker.io. The latter is a more robust solution indeed. Copying has a hack :(

Alidantech commented 3 months ago

I am facing this error in 2024. I have read through this issue but can't figure it out. I have docker installed on my ec2 instance and I installed jenkins via the official docker container. How can I resolve this error.