Docker 安装Jenkins

Docker 安装Jenkins

Scroll Down

Docker 安装jenkins

因为官方jenkins镜像不能直接用

Dockerfile 文件

因为jenkins 可能涉及docker命令所以先安装docker在安装docker-compose
在因为jenkins全局配置需要java与maven 所以安装java与maven

FROM jenkins/jenkins:lts
MAINTAINER bing_huang <[email protected]>
USER root
##快速 sh脚本
RUN curl -fsSL get.docker.com -o get-docker.sh
RUN sh get-docker.sh --mirror Aliyun

COPY daemon.json /etc/docker/daemon.json

# 安装 Docker Compose
WORKDIR /usr/local/bin
RUN wget https://raw.githubusercontent.com/topsale/resources/master/docker/docker-compose
RUN chmod +x docker-compose

# 安装 Java
RUN mkdir -p /usr/local/java
WORKDIR /usr/local/java
COPY jdk-8u152-linux-x64.tar.gz /usr/local/java
RUN tar -zxvf jdk-8u152-linux-x64.tar.gz && \
    rm -fr jdk-8u152-linux-x64.tar.gz

# 安装 Maven
RUN mkdir -p /usr/local/maven
WORKDIR /usr/local/maven
RUN wget https://raw.githubusercontent.com/topsale/resources/master/maven/apache-maven-3.5.3-bin.tar.gz

RUN tar -zxvf apache-maven-3.5.3-bin.tar.gz && \
    rm -fr apache-maven-3.5.3-bin.tar.gz


# 配置环境变量
ENV JAVA_HOME /usr/local/java/jdk1.8.0_11
ENV MAVEN_HOME /usr/local/maven/apache-maven-3.5.3
ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin

WORKDIR /

docker-compose.yml 文件

version: "3.1"
services:
   jenkins:
     image: jenkins
     volumes:
       - ./jenkins_home:/var/jenkins_home
       - /var/run/docker.sock:/var/run/docker.sock
     ports:
       - '8089:8080'
       - '50000:50000'
     restart: always
     container_name: jenkins
     environment:
       JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
     networks:
       jenkins:
          aliases:
             - jenkins_networks
networks:
   jenkins:

daemon.json 文件 中国镜像加速

{
	"registry-mirrors":[
		"https://registry.docker-cn.com",
		"https://i27azkms.mirror.aliyuncs.com"
	]
}

登录

ip:8089
登录后选择推荐安装插件 安装完成之后请修改 登录密码

用户管理

安装插件

系统管理-插件管理
插件:

Maven Integration,Publish Over SSH等常用插件

java与maven 配置

路径

系统管理-全局工具配置