Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of building Jenkins construction environment under Docker

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First of all, we need to build a linux system in the docker environment. There are so many tutorials that I won't repeat them here.

Then write a dockerfile to generate an image. Dockerfile is actually a collection of commands, a bit like windows's batch file.

To build a Jenkins build environment, you need to install jdk, maven, tomcat, and jenkins, as well as GIT, which is used to build the code from GIT, as follows:

FROM centos:7 # author infoMAINTAINER xulijian 514045152@qq.com# install wget to download filesRUN yum install wget-y # install gitRUN yum install git-yRUN cd / opt# download jdkRUN wget-- no-check-certificate-- no-cookies-- header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz# download mavenRUN wget http://mirrors.hust.edu.cn/apache/maven/maven- 3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz# download tomcatRUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.15/bin/apache-tomcat-8.5.15.tar.gz# unzip jdkRUN tar-xvf jdk-8u131-linux-x64.tar.gz-C / opt/# unzip mavenRUN tar-xvf apache-maven-3.5.0-bin.tar.gz-C / opt/# unzip TomcatRUN tar-xvf apache-tomcat-8.5.14.tar.gz-C / opt# set environmentENV JAVA_HOME/ opt/jdk1.8.0_131ENV MAVEN_HOME/ opt/apache-maven-3.5.0ENV CLASSPATH.: $JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarENV PATH $JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH# download jenkinsRUN wget-P / opt/apache-tomcat-8.5.14/webapps Http://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.46.2/jenkins.war# startup tomcatCMD / opt/apache-tomcat-8.5.14/bin/catalina.sh run# expose memcached portEXPOSE 8080

Then execute the build command

Docker build-t liuge1988/jenkins:base-f / opt/test/dockerfile / opt/test

-t the image to be generated, user/repo:tag

-f path where the dockerfile file is located

/ opt/test can be any directory. Copy to the directory of the newly generated image synchronously to initialize the contents of the directory

After the execution is complete, check to see if the image is generated correctly.

Docker images | grep Jenkins

After the image is generated, you can store the image in docker hub. When you want to use it in the future, just pull it down from the docker hub.

To upload to docker hub, you need to register a docker hub account and type the command.

Docker login

Enter your user name and password when prompted, and if you prompt login success, you have successfully logged in.

Then execute the push command to upload the image to docker hub

Docker push user/repo:tag

User/repo:tag user / repository: image tags, such as liuge1988/jenkins:base

After the image is generated, you can use the image to start a specific container.

Docker run-d-I-t-- name jenkins_procloud-p 8308 liuge1988/jenkins:base 8080

After the startup is complete, execute the command to see if the container is running successfully.

Docker images | grep Jenkins

The container is actually a lightweight linux, which is the same as the linux system after entering the container. If you want to enter the container and perform some operations, you can execute the following command.

Docker exec-it containerId / bin/bash

To exit the container, type exit or Ctrl + D.

Go to the bin directory of tomcat and start tomcat

After starting tomcat, you can access jenkins through the host ip: Port / jenkins.

Http://192.168.1.111:8308/jenkins

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report