Docker and Jenkins with chroot-based SDK

How to run Jenkins via docker and build a project chrooting in a SDK?

Easy

docker is easy to install on Ubuntu [1].

Starting a Jenkins container with a persistent volume is just as easy [2]:

sudo docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins

Restarting the container with the volume keeps being easy:

sudo docker run --volumes-from myjenkins -p 8080:8080 jenkins

Not so easy

The problems come when you try to chroot into the SDK:

clone: Operations not permitted

Solution Run docker in privileged mode with the command-line parameter --privileged.

Still not working?

mount failed: /dev/console -> dev/console (mount: No such file or directory)

Solution Run in terminal interactive mode with the command-line parameter -t.

Final command

sudo docker run -t --privileged --volumes-from myjenkins -p 8080:8080 jenkins

Wait, I need some more tools

FROM jenkins

USER root
RUN apt-get update && apt-get install -y lbzip2 && rm -rf /var/lib/apt/lists/*

USER jenkins

References

[1]Docker docs, Ubuntu installation, https://docs.docker.com/engine/installation/linux/ubuntu/
[2]Docker library, Jenkins container, https://hub.docker.com/_/jenkins/