-1

I just started learning docker and Jenkins and wanted to run Jenkins inside a Docker container.

  • I'm referring to this repo on github. It has a Dockerfile (Dockerfile link) that uses openjdk:8-jdk-stretch as its base image

  • I want to use centOS/any other smaller base image.

  • I tried writing FROM centOS instead of FROM openjdk:8-jdk-stretch but that didn't work.
  • I want it to run on HTTP port 9090 and AGENT port on 55000.

The output that I got looks like this Output

So this is what I did with the Dockerfile.

FROM openjdk:8-jdk-stretch
RUN apt-get update && apt-get install -y git curl && rm -rf/var/lib/apt/lists/*
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000
ARG http_port=9090
ARG agent_port=55000

Keeping all other changes same according to this Dockerfile ( Dockerfile Link )

I want my container to run Jenkins on CentOS/any other smaller base image and able to push that container image to my DockerHub. I'm struck, any bits of help/lead will be appreciated.

Rajat Singh
  • 653
  • 6
  • 15
  • 29

1 Answers1

2

Jenkins image size

If you want a smaller image, just use one of the following image tags:

  • jenkinsci/jenkins:2.154-slim (408 MB)
  • jenkinsci/jenkins:2.154-alpine (222 MB)

Publishing ports

Now for the ports. The ports opened within the container don't matter since docker will offer you the ability to publish them to whatever port you choose on the docker host.

In short, start your container with:

docker run -d \
    -p 9090:8080 \
    -p 55000:50000 \
    jenkinsci/jenkins:2.154-alpine

Adding files to the Jenkins container

If you need to add files to the Jenkins container, just use a volume:

docker run -d \
    -p 9090:8080 \
    -p 55000:50000 \
    -v /home/somewhere/workspace/:/my_data \
    jenkinsci/jenkins:2.154-xxxx

Adding software to the Jenkins image

jenkinsci/jenkins:2.154-slim

The slim flavor image is based FROM openjdk:8-jdk-slim which itself is based FROM debian:stretch-slim. Now that we know it is based on Debian, installing software can be done with `ap

FROM jenkinsci/jenkins:2.154-slim 
USER root
RUN apt-get update \
    && apt-get install -y \
      curl \
      git \
    && rm -rf/var/lib/apt/lists/*
USER jenkins

jenkinsci/jenkins:2.154-alpine

In Alpine flavored images, you install software with apk.

FROM jenkinsci/jenkins:2.154-alpine 
USER root
RUN apk --update add \
      curl \
      git 
USER jenkins

CentOS Jenkins image

There is no official Jenkins docker images based on CentOS. While Making your own is possible, the time you will spend coming up with a working Dockerfile and the time you will have to spend to maintain it is most likely no worth the added value it would bring to you.

Thomasleveil
  • 95,867
  • 15
  • 119
  • 113