I went to an FSOSS 2016  conference and I found one talk on Jenkins to be particularly interesting.
I wanted to try Jenkins, without configuring Java on my laptop or setting up a VM. Using Jenkins docker container would be the easiest solution for this kind of problem.
I used an official container built by Jenkins community .
The container comes with these settings:
- Jenkins server runs on ports 5000 and 8000
- Jenkins settings saved to /var/jenkins_home and the directory is exposed as a docker volume
- user / group ids are set to jenkins / jenkins with uid/gid set to 1001/1001.
Docker volume settings, specify container directory mapping between host and container , allowing files generated inside of the container to persist. The host system will store the data in /srv/dockercontainer/jenkins_home.
Following steps to set up docker volume and permission mapping on the host.
- Create docker volume path on the host
# mkdir /srv/dockercontainer/jenkins_home
- Set up user/group mapping on the host.
# groupadd --gid 20000 jenkins # useradd --home-dir /srv/dockercontainer/jenkins_home \ --uid 20000 --gid 20000 -s /bin/false -M jenkins # chown -R jenkins:jenkins /srv/dockercontainer/jenkins_home
Docker compose file
docker-compose.yml specifies startup settings for Jenkins container.
version: '2' services: jenkins: image: jenkins user: "20000:20000" ports: - "5000:5000" - "8080:8080" volumes: - /srv/dockercontainer/jenkins_home:/var/jenkins_home
- image -- the directive specifies container to use, in this case it's Jenkins container .
- user -- user/group mapping, 'uid:gid' from the container is mapped 'uid:gid' of the host.
- ports -- port mapping from the container to the host.
- volumes -- directory (docker volume) mapping, between the host and the container.
Starting up the container
Go to the directory containing docker-compose.yml.
The following command starts the container in foreground, the container needs to be run in the foreground, as during the setup, system activation code for Jenkins will be printed to the console.
# docker-compose up
Open a browser and go to http://localhost:8080. Once initial setup is completed, stop the container with Ctrl+C, then start it as a daemon.
# docker-compose up -d
To shut down the container running in daemon mode, execute the following.
# docker-compose stop
Deleting the container
To remove container setup, run the following command from the directory where docker-compose.yml is located.
# docker-compose rm jenkins
The data generated by Jenkins in docker container is saved in /srv/dockercontainer/jenkins_home with user 'jenkins' and group 'jenkins'.
|||FSOSS 2016 -- http://cdot.fsoss.ca/2016/|
|||Docker installation on Debian -- https://docs.docker.com/engine/installation/linux/debian/|
|||Install Compose -- https://docs.docker.com/compose/install/|
|||Official Jenkins Docker image -- https://hub.docker.com/_/jenkins/|
|||Manage data in containers -- https://docs.docker.com/engine/tutorials/dockervolumes/|