Docker常用镜像的构建脚本及jenkins手动触发镜像构建

1、centos镜像的二次封装
docker build -t csphere/centos:7.1 .
docker build -t csphere/centos:7.1 .

 

FROM       centos:centos7.1.1503
MAINTAINER Carson,C.J.Zeong 

ENV TZ "Asia/Shanghai"
ENV TERM xterm

ADD aliyun-mirror.repo /etc/yum.repos.d/CentOS-Base.repo
ADD aliyun-epel.repo /etc/yum.repos.d/epel.repo

RUN yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
    yum install -y gcc gcc-c++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel && \
    yum install -y --enablerepo=epel pwgen python-pip && \
    yum clean all

RUN pip install supervisor
ADD supervisord.conf /etc/supervisord.conf

RUN mkdir -p /etc/supervisor.conf.d && \
    mkdir -p /var/log/supervisor

EXPOSE 22

ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

注意:这步很重要否则会导致后续的很多镜像构建出问题(每个镜像都有相互依赖),建议不要“创新”否则会话更多的时间去修复“创新”

2、jdk1.8镜像 
docker build -t csphere/jdk:1.8 .
docker run -d -p 18083:8083 --name jdk1.8 csphere/jdk:1.8  

FROM       csphere/centos:7.1 
MAINTAINER [email protected]
 
USER root


ADD  jdk1.8 /usr/local/jdk1.8


#安装jdk
ENV  JAVA_HOME /usr/local/jdk1.8 
ENV  JRE_HOME  /usr/local/jdk1.8/jre 
ENV  PATH      $PATH:$JAVA_HOME/bin:$JRE_HOME/bin 
ENV  CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib 

3、maven镜像 
docker build -t csphere/maven:3.3.9 .
docker run  -d -p 18081:8081   --name maven3.3.9   csphere/maven:3.3.9

FROM       csphere/jdk:1.8
MAINTAINER lzhcode

ENV MAVEN_VERSION 3.3.9
ENV MAVEN_HOME /usr/local/maven

# Install maven
# ADD http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz /usr/local/

USER root

RUN   mkdir -p /usr/local/ 

COPY apache-maven-${MAVEN_VERSION}-bin.tar.gz  /usr/local/apache-maven-${MAVEN_VERSION}-bin.tar.gz


RUN    cd /usr/local && \
       tar -xvf  apache-maven-${MAVEN_VERSION}-bin.tar.gz -C /usr/local && \
       mv   apache-maven-${MAVEN_VERSION} maven  && \
       rm -rf   apache-maven-${MAVEN_VERSION}-bin.tar.gz


RUN    ln -s /usr/local/maven/bin/mvn /usr/bin/mvn && \
       chmod 777 /usr/bin/mvn

COPY settings.xml /usr/local/maven/conf/settings.xml

ADD hello /hello
RUN cd /hello && \
    mvn clean install -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true

4、tomcat镜像
docker build -t csphere/tomcat:7.0 .
docker run -d -p 18082:8082 --name tomcat7.0 csphere/tomcat:7.0

FROM       csphere/jdk:1.8
MAINTAINER lzhcode

ENV TOMCAT_MAJOR_VERSION 7
ENV TOMCAT_MINOR_VERSION 7.0.68
ENV CATALINA_HOME /usr/local/tomcat7.0
ENV APP_DIR ${CATALINA_HOME}/webapps/

# Install tomcat
# RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz

RUN   mkdir -p /usr/local/

COPY  apache-tomcat-*.tar.gz  /usr/local/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz

RUN   cd /usr/local && \
      tar zxf apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz  && \
	  mv apache-tomcat-${TOMCAT_MINOR_VERSION} tomcat7.0    && \
      rm -rf  apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz   
  
RUN   cd  ~/ 
ADD   scripts /scripts
RUN   chmod -R 777 /scripts


EXPOSE 8080 8443

ENTRYPOINT ["/scripts/run"]

ONBUILD ADD . ${APP_DIR}

5、jenkins镜像

docker build -t  csphere/jenkins:2.138 .
docker run -d -p 18080:8080   --name jenkins   -v /usr/bin/docker:/usr/bin/docker -v /etc/sysconfig/docker:/etc/sysconfig/docker -v /run/docker.sock:/run/docker.sock -v /usr/local/docker-training/maven:/root csphere/jenkins:2.138

 

#
# MAINTAINER        Carson,C.J.Zeong 
# DOCKER-VERSION    1.6.2
#
# Dockerizing Jenkins: Dockerfile for building Jenkins images
#
FROM       csphere/jdk:1.8
MAINTAINER Carson,C.J.Zeong 

ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_VERSION 2.138
ENV JENKINS_UC https://updates.jenkins-ci.org
ENV COPY_REFERENCE_FILE_LOG /var/log/copy_reference_file.log


RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d && \
    mkdir -p $JENKINS_HOME 

COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy

COPY jenkins.war  /usr/share/jenkins/jenkins.war

RUN chown -R root "$JENKINS_HOME" /usr/share/jenkins/ref && \
    touch $COPY_REFERENCE_FILE_LOG && chown -R root $COPY_REFERENCE_FILE_LOG


VOLUME /var/jenkins_home

EXPOSE 8080 50000

COPY jenkins.sh /usr/local/bin/jenkins.sh


RUN   chmod +x   /usr/local/bin/jenkins.sh  

ENTRYPOINT ["/usr/local/bin/jenkins.sh"]

5.1手动构建 jenkins镜像

Docker常用镜像的构建脚本及jenkins手动触发镜像构建_第1张图片

Docker常用镜像的构建脚本及jenkins手动触发镜像构建_第2张图片

Docker常用镜像的构建脚本及jenkins手动触发镜像构建_第3张图片

Docker常用镜像的构建脚本及jenkins手动触发镜像构建_第4张图片

出现的问题:
1.You don't have either docker-client or docker-client-latest installed. Please install either one and retry.
docker默认要在docker用户下才能运行刚开始使用了jenkins用户结果无法运行docker命令

2.切到root用户后仍然提示上面的语句,原来是没有安装docker-client 执行进入容器执行
yum clean all && yum swap fakesystemd systemd
yum install docker-client
应该是centos的版本比较旧的原因,提交centos7.1镜像前先执行这两句

3.最新的jenkins2.138下好像没有docker client命令行工具(知道原因的同学欢迎指正),因此我们只需要传递DOCKER_HOST环境变量 或者映射docker.sock文件给jenkins容器,就可以让jenkins容器里面拥有docker的操作能力,进而将两者结合起来。

4.Rpmdb checksum is invalid: dCDPT(pkg checksums): sudo.x86_64 0:1.8.6p3-29.el6_9 - u
rpm数据库损坏需要重建。因此需要在 “yum install …” 前使用“rpm –rebuilddb” 重建数据库。比如:
RUN rpm --rebuilddb && yum install -y sudo ...

你可能感兴趣的:(云计算/大数据)