基础容器镜像
https://hub.docker.com/r/skiychan/nginx-php7/
docker pull skiychan/nginx-php7 #或者 docker pull registry.cn-shenzhen.aliyuncs.com/leiyankeji/dev-test
1.Jenkins上执行的脚本如下
#!/bin/bash #Author:Benson #Blog:http://www.qinzc.me #Time:2018-11-22 09:30:55 #Name:devops.sh #Version:V1.0 #Description: jenkins CI shell CODEDIR=/data/code echo "############git pull new code....#############" cd $CODEDIR rm -fr $CODEDIR/dockertest git clone http://192.168.1.22/hechuanzhang/dockertest.git #pull下来的代码,删除.git隐藏文件 rm -fr ${CODEDIR}/dockertest/.git # 先删除之前的容器 echo "remobe old container" docker ps -a | grep nginx | awk '{print $1}'| xargs docker rm -f # 删除之前的镜像 echo "romove old image" docker rmi qinzc/nginx # 构建镜像 docker build -t qinzc/nginx /data/code/. # 打印当前镜像 echo "print docker images" docker images # 启动容器 echo "start container" docker run --name nginx -p 8080:80 -d qinzc/nginx # 打印当前容器 echo "print container" docker ps -a echo "star service success!"
2.Dockerfile 文件如下
# Dockerfile #create a images FROM registry.cn-shenzhen.aliyuncs.com/leiyankeji/dev-test MAINTAINER qinzicheng "542129333@qq.com" #copy files to new images COPY "/dockertest" /data/www EXPOSE 80 443 ENTRYPOINT /start.sh
jenkins触发后执行结果如下。
请登录后查看评论内容