dind-jenkins-slave icon indicating copy to clipboard operation
dind-jenkins-slave copied to clipboard

Unable to use docker because of the plugin default CMD

Open SylvestreMassalaz opened this issue 9 years ago • 4 comments

Hi there, I currently have a problem when using this image that seems to come from the docker plugin configuration.

Either I leave the CMD field unmodified and the docker command fails because the startup script is not launched or I try to set it to the startup script and the SSH connection fails.

I didn't find any hints in the plugin documentation, but I noticed that the default command doesn't looks like the default one (see the result i got from a docker inspect below):

  • The default one
"Path": "bash",
"Args": [
    "-c",
      "/usr/sbin/sshd -D -p 22"
],
  • The custom one
"Path": "/jenkins-slave-startup.sh",
"Args": [],

Does anyone know how to set it correctly?

SylvestreMassalaz avatar Aug 14 '15 09:08 SylvestreMassalaz

We do this:

We have an image that uses this as it's base, so something like:

FROM tehranian/dind-jenkins-slave

COPY docker-entrypoint.sh /entrypoint
ENTRYPOINT ["/entrypoint"]

Then our docker-entrypoint.sh:

#!/bin/bash
set -e

case "$1" in
  image | test | deploy)
    cd /home/jenkins && exec wrapdocker sudo -EHsu jenkins ci-${1}.sh;
esac

exec wrapdocker "$@"

Basically, everything just needs to call wrapdocker which is what controls starting the daemon in the background.

Does that make sense?

mattrobenolt avatar Aug 14 '15 14:08 mattrobenolt

@mattrobenolt Is changing our Dockerfile to work better out of the box an option?

tehranian avatar Aug 14 '15 16:08 tehranian

Likely, I'm not even sure why sshd is needed tbh since we don't use it.

But I'd rather let @branden answer better since he mostly works on this stuff. I'm just a spectator mostly. :)

mattrobenolt avatar Aug 14 '15 16:08 mattrobenolt

Hi, thanks for your response!

Sadly, I'm still unable to make it work correctly, this time even with the default command set by the jenkins docker plugin.

As you can see I only added a few things when starting from your example

FROM tehranian/dind-jenkins-slave
MAINTAINER Sylvestre Massalaz <[email protected]>

ENV YML_DIR /etc/pl/

RUN curl -L -k https://github.com/docker/compose/releases/download/1.3.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose &&\
    chmod +x /usr/local/bin/docker-compose

RUN apt-get update &&\
    apt-get install -y \
      wget \
      curl \
      unzip

COPY pl-deploy-test/* ${YML_DIR}

COPY compose-entrypoint.sh /entrypoint

RUN chmod +x /entrypoint

ENTRYPOINT ["/entrypoint"]

My entrypoint is also really simple

#! /bin/bash

set -e

exec wrapdocker "$@"

When it's launched with the plugin default command, I get this with docker inspect

    "Path": "/entrypoint",
    "Args": [
        "bash",
        "-c",
        "/usr/sbin/sshd -D -p 22"

Then I tried to remove the bash (the command being already inside an exec) and I mannually set it to /usr/sbin/sshd -D, the ni got

    "Path": "/entrypoint",
    "Args": [
        "/usr/sbin/sshd",
        "-D"
    ],

Either way, the container is created by Jenkins but the SSH connexion seems to fail because it shows offline and never starts the build.

The only setting I made on the template configuration is checking "run privileged" as asked in the readme.

Any Idea?

Edit : I think that the error with ssh has something to do with the fact that wrapdocker seems to take a while, maybe never launching the default command. Maybe we should use a smaller version that only does the basic configuration and daemon starting?

SylvestreMassalaz avatar Aug 17 '15 08:08 SylvestreMassalaz