Containerized Jenkins master and agents

27 views
Skip to first unread message

Daniele Riccucci

unread,
Mar 18, 2019, 2:21:01 AM3/18/19
to Jenkins Users
Hello,
I recently switched to running Jenkins from host machine to a docker
container (https://hub.docker.com/r/jenkins/jenkins).
I was also using docker agents to build. This is now broken in my
current setup as I'm spinning up a slave container to run pipelines and
issues arise in a situation such as:

pipeline {
agent { label 'jnlp-agent-docker' }
// this is the major change as before it was not a container,
// the label refers to a template with a similar version of
// https://github.com/jenkinsci/jnlp-agents/ > docker
stages {
stage('Build') {
agent {
docker { // could also be dockerfile
image "<myimage>"
}
}
steps {
git 'myrepo'
sh "build"
archiveArtifacts artifacts: 'dist/**/*'
}
}
}
}

The docker plugin (this one >
http://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin) is obviously
unable to mount workspaces in another container and builds fail.
I would like to avoid adding a new template for this and using docker in
docker
(https://support.cloudbees.com/hc/en-us/articles/360001566111-Set-up-a-Docker-in-Docker-Agent-Template)
if possible
(https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/),
but I'll adapt to whatever works.

Is there a correct way to build using containers for jenkins, and the
slaves?

Thank you.

nicolas de loof

unread,
Mar 18, 2019, 3:43:42 AM3/18/19
to jenkins...@googlegroups.com
Hi.

Why do you use some "jnlp-agent-docker" agent as you then switch to another one, based on a docker image ? Why not just use the later for the whole build ?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9fb2d785-1b74-c0d4-dd05-4b072e8efe59%40posteo.net.
For more options, visit https://groups.google.com/d/optout.


--
Nicolas De Loof

Daniele Riccucci

unread,
Mar 18, 2019, 1:27:19 PM3/18/19
to jenkins...@googlegroups.com
Hello,

thank you for the reply. I did try, however there are a few reasons why
that didn't work for me:

* the jnlp-agent-docker, being based on openjdk at its root, doesn't
have several build tools more readily available on other images

* the agent specifically has the jnlp-slave built-in which eases
communication, most images would require `docker attach`

* the official jenkins/jenkins image doesn't seem to be natively able to
run docker containers, for example the following pipeline:

pipeline {
agent {
docker {
image "golang:1.12-alpine"
}
}
stages {
stage('Build') {
steps {
git '<myrepo'
sh "go get ./..."
sh "go build ."
}
}
}
}

fails when it tries to execute the `docker login` command as it's not
present.
This forced me to use the jnlp-agent which *does* have the docker
command and mounts the /run/docker.sock from the host (or connects via TLS)

* such a workaround however does not support launching a second
container and would require a different, customized image for every
pipeline as a "Docker Agent template" configured in Jenkins, which is
very cumbersome

It is very possible I'm missing something or misconfigured my Jenkins
master but this is what I'm experiencing.

Regards,
Daniele

On 18/03/19 08:43, nicolas de loof wrote:
> Hi.
>
> Why do you use some "jnlp-agent-docker" agent as you then switch to
> another one, based on a docker image ? Why not just use the later for
> the whole build ?
>
> Le lun. 18 mars 2019 à 07:20, Daniele Riccucci <dev...@posteo.net
> <mailto:dev...@posteo.net>> a écrit :
> <mailto:jenkinsci-users%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/9fb2d785-1b74-c0d4-dd05-4b072e8efe59%40posteo.net.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Nicolas De Loof
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jenkinsci-use...@googlegroups.com
> <mailto:jenkinsci-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/CANMVJzmAcGFLmMmHd_TOpYHgZ%2Bw4fz%2BinQS3wEfeSrG-fNGDsg%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CANMVJzmAcGFLmMmHd_TOpYHgZ%2Bw4fz%2BinQS3wEfeSrG-fNGDsg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages