实现功能:
- 拉取 centos 镜像,安装 wget、jdk、git、maven 软件,并设置环境变量
- 下载代码,并执行测试用例
Dockerfile 文件
FROM centos
ADD entrypoint.sh /root
ADD jdk /usr/local/jdk/
RUN yum install -y wget
RUN yum install -y git
RUN wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
RUN tar -zxvf apache-maven-3.6.3-bin.tar.gz
RUN mv apache-maven-3.6.3 /usr/local
ENV JAVA_HOME=/usr/local/jdk/
ENV MAVEN_HOME=/usr/local/apache-maven-3.6.3
ENV PATH=$PATH:$MAVEN_HOME/bin:$JAVA_HOME/bin
ENTRYPOINT ["/bin/bash","/root/entrypoint.sh"]
上面多条的 RUN 命令也可以合并执行,替换成
RUN yum install -y wget \ && yum install -y git \ && wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz \ && tar -zxvf apache-maven-3.6.3-bin.tar.gz \ && mv apache-maven-3.6.3 /usr/local
entrypoint.sh 文件
#/bin/bash
git clone https://github.com/ycwdaaaa/techUI
cd techUI
mvn test
最后用docker build -t newimage .
在当前工作目录下打一个镜像
参考https://www.cnblogs.com/panwenbin-logs/p/8007348.html
docker pull registry
docker run -d -p 5000:5000 -v /usr/local/registry:/var/lib/registry --restart=always --name registry registry:latest
# --restart=always 此参数保证当docker重启后,容器也会重新启动 -v 宿主机目录挂载到容器中
docker pull busybox #拉取busybox镜像
docker tag busybox localhost:5000/bosybox:v1.0 #打tag
docker push localhost:5000/bosybox:v1.0 #push到私有镜像仓库
curl http://localhost:5000/v2/_catalog