Skip to content

Instantly share code, notes, and snippets.

@keidrun
Last active November 11, 2018 11:41
Show Gist options
  • Save keidrun/658d07b2ebc50f69aff054a32ee0962b to your computer and use it in GitHub Desktop.
Save keidrun/658d07b2ebc50f69aff054a32ee0962b to your computer and use it in GitHub Desktop.
Building a latest Jenkins with master/slave on Docker

Build Master/Slave

Generate SSH keys

docker-compose up --build -d
docker-compose exec master ssh-keygen -t rsa -b 4096 -C ""

Set a public key

Check a public key and edit JENKINS_SLAVE_SSH_PUBKEY in docker-compose.yml.

cat jenkins_home/.ssh/id_rsa.pub
vi docker-compose.yml
...
    environment:
      - JENKINS_SLAVE_SSH_PUBKEY=ssh-rsa AAAAB3NzaC...
...

Set a private key

Check a private key and set it in Jenkins GUI.

cat jenkins_home/.ssh/id_rsa

Note

Alpine image sometimes make problems like NodeJS Plugin. I recommend to use Ubuntu image of default.

version: "3"
services:
master:
build: .
ports:
- 8080:8080
- 50000:50000
volumes:
- ./jenkins_home:/var/jenkins_home
links:
- slave01
slave01:
image: jenkinsci/ssh-slave
environment:
- JENKINS_SLAVE_SSH_PUBKEY=ssh-rsa AAAAB3NzaC...
version: "3"
services:
master:
build: .
ports:
- 8080:8080
volumes:
- ./jenkins_home:/var/jenkins_home
FROM jenkins
USER root
RUN cd tmp/ \
&& wget https://updates.jenkins-ci.org/latest/jenkins.war \
&& mv ./jenkins.war /usr/share/jenkins/
USER jenkins
FROM jenkins:alpine
USER root
RUN apk --no-cache add openssl
RUN cd tmp/ \
&& wget https://updates.jenkins-ci.org/latest/jenkins.war \
&& mv ./jenkins.war /usr/share/jenkins/
USER jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment