Install Jenkins on Docker's CentOS

1. How to use Jenkins with Docker

There are two possible methods:

1.1. Use official image

If your goal is simply to use Jenkins, it's a good idea to use the official Jenkins image below.

Official image of Docker Hub The version of jenkins seems to be old.

jenkins - Docker hub [Image ID] jenkins: latest [Version] v2.60.3 (as of August 28, 2020)

Jenkins / jenkins, which has a site on Github, seems to be the latest.

jenkinsci/docker: Docker official jenkins repo [Image ID] jenkins / jenkins: lts [Version] v2.235.5 (as of August 28, 2020)

1.2. Install on OS image

It can also be installed with the packages required for an OS image such as CentOS.

centos - Docker Hub

2. Install Jenkins on CentOS

This time, I tried how to install Jenkins on CentOS.

2.1. Dockerfile Normally, when installing a service such as Jenkins on CentOS, the start and end of the service is managed by systemd. However, since Docker's basic idea is to create a container for each process, systemd is not enabled in the official image of __CentOS. __

Therefore, I created a Dockerfile considering how to enable __systemd described on the official website.

Systemd integration: Dockerfile for systemd base image https://hub.docker.com/_/centos?tab=description

Below is the part referenced by __ other than the second RUN of the Dockerfile. The first RUN and VOLUME seem to be the main content, but Jenkins started __ without this __. However, if you leave the default as shown below, it says "might cause issues", so it seems better to have it.

This Dockerfile deletes a number of unit files which might cause issues. (Google Translate: This Dockerfile removes some unit files that can cause problems.)

Dockerfile


FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; \
     for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
    rm -f /lib/systemd/system/multi-user.target.wants/*; \
    rm -f /etc/systemd/system/*.wants/*; \
    rm -f /lib/systemd/system/local-fs.target.wants/*; \
    rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
    rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
    rm -f /lib/systemd/system/basic.target.wants/*; \
    rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 8080
RUN yum install -y java wget initscripts && \
    cd /etc/yum.repos.d && \
    wget http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo && \
    rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key && \
    yum install -y jenkins && \
    systemctl enable jenkins
CMD ["/sbin/init"]

I also refer to the operation commands.

Operation command


docker build --rm -t <Image name:tag> .
docker run -it -d --privileged --name <Container name> -h <hostname> -p 8080:8080 <Image name:tag>

2.2. Supplement

2.2.1. initscripts package

The CentOS image does not include the __initscripts package __. If you do not add it with the yum command, the startup process itself will result in an error and will not be executed, so you need to add it in advance.

The following first starts the container with the image built without including the __initscripts package __. After that, it is an error when entering the container and executing the "systemctl start jenkins" and "systemctl status jenkins" commands again.

bash


[root@localhost /]# systemctl start jenkins
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
[root@localhost /]#
[root@localhost /]# systemctl status jenkins
‚óŹ jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-08-27 01:31:06 UTC; 5s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 88 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)

Aug 27 01:31:06 localhost systemd[1]: Starting LSB: Jenkins Automation Server...
Aug 27 01:31:06 localhost jenkins[88]: /etc/rc.d/init.d/jenkins: line 59: /etc/init.d/functions: No such file or directory
Aug 27 01:31:06 localhost systemd[1]: jenkins.service: control process exited, code=exited status=1
Aug 27 01:31:06 localhost systemd[1]: Failed to start LSB: Jenkins Automation Server.
Aug 27 01:31:06 localhost systemd[1]: Unit jenkins.service entered failed state.
Aug 27 01:31:06 localhost systemd[1]: jenkins.service failed.
[root@localhost /]#

Aug 27 01:31:06 localhost jenkins[88]: /etc/rc.d/init.d/jenkins: line 59: /etc/init.d/functions: No such file or directory

It is an error because __ /etc/init.d/functions__ does not exist.

bash


[root@localhost /]# ls -l /etc/init.d/functions
ls: cannot access /etc/init.d/functions: No such file or directory
[root@localhost /]#

2.2.2. Checking the package that contains /etc/init.d/functions

If you look up "yum provides" to find out which yum package contains __, you will find that it is a initscripts package. However, it did not match in "/etc/init.d/functions", but it matched in "* /init.d/functions".

Symbolic links are heavily used in Linux. Please note that the file name including the displayed path is not always the original name __. If you search only by functions, it will match a lot, so I deleted the directory little by little.

bash


[root@localhost /]# yum provides */init.d/functions*
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp-srv2.kddilabs.jp
 * extras: ftp-srv2.kddilabs.jp
 * updates: ftp-srv2.kddilabs.jp
initscripts-9.49.49-1.el7.x86_64 : The inittab file and the /etc/init.d scripts
Repo        : base
Matched from:
Filename    : /etc/rc.d/init.d/functions

[root@localhost /]#

2.2.3. CentOS version

This Dockerfile uses CentOS: 7, but when I tried it with CentOS: 8, I got an error. Maybe it's because CentOS 8's default container engine is now Podman instead of Docker (a delusion). Details have not been confirmed.

Recommended Posts

Install Jenkins on Docker's CentOS
Install Golang on CentOS 8
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Install OpenFOAM v2006 on CentOS
Install Apache on CentOS on VirtualBox
Install Ruby 2.7 on CentOS 7 (SCL)
Install Java Open JDK 8 on CentOS 7
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
Install Java 9 on windows 10 and CentOS 7
Install samba4 from source code on CentOS8
Install the webmail client Rainloop on CentOS 8
How to install beta php8.0 on CentOS8
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
Install CentOS 7 on Raspberry pi 4 Model B
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Install GitLab on CentOS 8 with no internet connection
Install the latest version of Jenkins on Ubuntu 16
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Install Corretto 8 on Windows
Maven on CentOS 7 tutorial
Install OpenJDK on macOS
Install Java on Mac
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install pyqt5 on ubuntu
Try OpenLiteSpeed on CentOS8
Tomcat v8 on CentOS7
Install Docker on Manjaro
Zabbix 5 installation on CentOS 8
Install Ruby on Ubuntu 20.04
Use mod_auth_cas on CentOS 8
Install lombok on SpringToolSuite4
Use bat on Centos.
Jetty v8 on CentOS7
Install Autoware on Ubuntu 18.04.5
OpenJDK installation on CentOS 7
Install openjdk11 on mac
Install Homebrew on Ubuntu 20.04
Install OpenJDK 8 on mac
Install BookStack Documentation Wiki on Elastic Compute Service on CentOS 7
Install the latest hardware drivers from ELRepo on CentOS
Install MySQL 5.6 on CentOS6 [How to specify the version]
Install ag (the silver searcher) [on CentOS / Ubuntu / Mac]
Try RabbitMQ + PHP on CentOS
Install Docker on Raspberry Pi
Install Docker on Windows 10 PRO
Network install CentOS 8 with Kickstart.