Implementation of docker+jenkins (ps. using dockerfile)

A friend asked two days ago, docker+jenkins integration.

I haven't done it before, but I just have time recently, and I'm also very interested, so I'll do it.

What is docker and how to install it, I will not explain it here, but only introduce some pits I have stepped on.

First of all, let's talk about docker. I use the image of centos7. There is no wget in it, and there is very little online information. The pit is also slowly stepped on by myself.

Let’s talk about the routing table first. I use Alibaba Cloud. After installing docker, the command will report an error. After searching, the routing table needs to be changed.

sudo route del -net 172.16.0.0 netmask 255.240.0.0 

Since I am not very familiar with Linux, I only know He needs to start some processes, such as prompting you docker -d, you can enter docker -d to see.

Then docker images, as shown in the figure below, after

 

the image is pulled, there is no change, and it is built based on this.

The preferred construction method is Dockerfile, and its convenience is still good.

Create a new file, use

touch Dockerfile
vi Dockerfile here

is the Dockerfile I wrote, you can copy it directly
Copy code

FROM centos:7

MAINTAINER yuxh [email protected]

RUN curl -o /etc/yum.repos.d/CentOS- Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
RUN sed -i.bak 's#aliyun\.com#aliyuncs.com#' /etc/yum.repos.d/CentOS-Base.repo
RUN yum install wget -y
RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz
RUN wget http://mirrors.aliyuncs.com/apache/tomcat/tomcat-7/v7.0.63/bin/apache-tomcat-7.0.63.tar.gz
RUN wget http://mirrors.aliyuncs.com/apache/ant/binaries/apache-ant-1.9.6-bin.tar.gz
RUN cd /opt
RUN tar -xvf apache-tomcat-7.0.63.tar.gz -C /opt/
RUN tar -xvf apache-ant-1.9.6-bin.tar.gz -C /opt/
RUN tar -xvf jdk-7u79-linux-x64.tar.gz -C /opt/
ENV JAVA_HOME /opt/jdk1.7.0_79
ENV ANT_HOME /opt/apache-ant-1.9.6
ENV CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $JAVA_HOME/bin:$ANT_HOME/bin:$PATH
RUN wget -P /opt/apache-tomcat-7.0.63/webapps http://mirrors.jenkins-ci.org/war/latest/jenkins.war
RUN yum install git -y
CMD /opt/apache-tomcat-7.0.63/bin /catalina.sh run
# expose memcached port
EXPOSE 8080Copy

code

The first line, which mirror is based on, I just said, the third line is just the contact information.

The following is to modify and add some development environments. Thanks to the help of friends in operation and maintenance, otherwise I really can't figure it out.

There is a line about the download of jdk above, which needs to skip oracle verification. Since it cannot be downloaded directly, here is the method found by Baidu.

The following uses ENV to configure the environment variable

CMD is the command executed after the build, here to start tomcat

EXPOSE 8080 Here is the port required by tomcat.

Save these after writing, and then execute the following command to build

docker build -t jenkins/centos:v1 .

Where -t jenkins/centos names the image, v1 is a label, followed by a ., which means that the process of finding the Dockerfile from the current directory

is very slow, please be patient. . . . .

After success, use the following command to run the image.

docker run -d -p 80:8080 jenkins/centos:v1

80:8080 means port mapping, mapping 8080 to 80.

If no error is reported here, you can access it by entering ip. If you

have any questions, you can ask me, anyway I don't know much either, 2333333

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326399363&siteId=291194637
Recommended