简体   繁体   中英

Dockerfile for Jenkins

I'm absolutely new in Docker and Jenkins and I want to try to ask you, maybe you are able to help me.

I want to create a Dockerfile with all necessarily Jenkins parts to be able to create an automated task for checking out a github.

So firstly I found the public dockerfile on github ( https://github.com/jenkinsci/docker/blob/master/Dockerfile ), but it includes a lot of parameters and I'm not sure, if is necessarily to use the whole Dockerfile.

Firstly, can you just give me an advice, how to modify the dockerfile? Or is recommended to use the original Dockerfile (URL is upper)?

Thank you for any advice, guys, have a nice day.

Don't modify the Dockerfile at all . Create a new Dockerfile that starts with:

FROM jenkins

And then place your changes below that. This will include everything in the official Jenkins image, and then add your customizations.

There are some pretty good docs on docs.docker.com , in particular this one talks about best practices for writing Dockerfiles.

这些 Docker images任何一个用作Dockerfile基础映像并创建。

The standard process is to extend upstream images. The only need to pull the Dockerfile from an upstream project and modify it directly is if you have a company policy that requires you to build everything from scratch, or upstream is doing something incorrect with their Dockerfile that you cannot correct by extending it (eg defining volumes in the Dockerfile). The reason for extending is that you can easily get the latest patches by pulling the upstream image and rebuilding your child images without trying to reapply their changes to your Dockerfile.

The "official" jenkins image on the Docker hub has moved around a few times. It used to be jenkinsci/jenkins, then it moved into the official library as jenkins:latest, and now it's moved to jenkins/jenkins:lts. An example of how you'd extend the upstream image looks like the below example:

FROM jenkins/jenkins:lts

ARG GOSU_VERSION=1.10

# switch to root, let the entrypoint drop back to jenkins
USER root

# install debian packages, gosu, and docker
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
     vim \
     wget \
 && dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
 && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
 && chmod +x /usr/local/bin/gosu \
 && gosu nobody true \
 && curl -sSL https://get.docker.com/ | sh \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

# entrypoint is used to update docker gid and revert back to jenkins user
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

I've got the rest of this example in my github repo: https://github.com/bmitch3020/jenkins-docker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM