【DevOps】jenkins+docker+harbor打包docker镜像到harbor镜像仓库

编写Dockerfile文件

FROM java:8
ADD springcloud-eureka-1.0-SNAPSHOT.jar /usr/local
WORKDIR /usr/local
ENTRYPOINT ["/bin/bash","-c","sh bin/eureka-app.sh && sleep 5 && tail -f /usr/local/applogs/springcloud-eureka-app.log"]

测试docker连接到harbor私有仓库服务

docker  login https://47.100.195.58:9080/harbor -uadmin

把harbor仓库ip加到docker配置中

echo '{ "insecure-registries":["47.100.195.58:9080"] }' > /etc/docker/daemon.json

构建镜像命令

docker build -t springcloud-eureka:v1 .

推送harbor命令(标记、推送)

docker tag springcloud-eureka:v1 47.100.195.58:9080/springcloud-app/springcloud-eureka:v1
docker push 47.100.195.58:9080/springcloud-app/springcloud-eureka:v1

这样镜像就推到远程私有仓库来了
【DevOps】jenkins+docker+harbor打包docker镜像到harbor镜像仓库_第1张图片

接下来使用流水线拉取git代码,使用挂载的maven编译代码,使用docker构建镜像,最后发布到harbor平台上

这里构建遇到docker not find

修改启动jenkins启动命令

docker run -d --name jenkins -p 8040:8080 -p 50000:50000 \
-v /usr/java/jdk1.8.0_161:/usr/java/jdk1.8.0_161 \
-v  /usr/java/jdk1.8.0_161/bin:/usr/java/jdk1.8.0_161/bin \
-v /usr/local/maven3.6:/usr/local/maven3.6 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/jenkins_home:/var/jenkins_home jenkins/jenkins

把/usr/bin下的docker也挂载进去

添加完成之后又报错

dial unix /var/run/docker.sock: connect: permission denied
gpasswd -a jenkins docker

重启docker后发现还是报错

给/var/run/docker.sock一个666的权限

chmod 666 docker.sock

你可能感兴趣的:(【DevOps】jenkins+docker+harbor打包docker镜像到harbor镜像仓库)