1.创建jenkins目录,并上传相应的包
mkdir /jenkins/
2.创建一个Dockerfile文件
FROM daocloud.io/library/centos:7#把当前目录下的jenkins.war包传到内部容器的/ 下
ADD ./jenkins.war /#把当前目录下的jdk传到内部容器的/opt/,并解压
ADD ./jdk-11.0.19_linux-x64_bin.tar.gz /optRUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
RUN yum clean all
RUN yum repolist
RUN yum -y install fontconfig#配置java环境
ENV JAVA_HOME=/opt/jdk-11.0.19
ENV PATH=${JAVA_HOME}/bin:${PATH}#启动jenkins命令
CMD [ "java","-jar","/jenkins.war" ]
3.构建jenkins镜像
docker build -t jenkins:1.0 .
4. 构建jenkins镜像过程
5.查看镜像
docker images
6.运行jenkins镜像
#-e 指定环境, -v 映射本地目录到容器里,-p 映射本地端口到容器
docker run -it -e JENKINS_HOME=/opt/.jenkins -v ./plugins:/opt/.jenkins/plugins -p 8080:8080 jenkins:1.0
7.查看正在运行的容器
docker ps
8.页面显示
9.进入到jenkins