前言
之前通过docker搭建过jenkins+python3环境,如果想要在不同的机器上搭建一样的环境,就可以将之前搭建的镜像上传到镜像仓库,这样方便在不同的机器上快速搭建同一套环境。
如果公开的话,别人也可以用你的镜像快速搭建环境,类似于 GitHub 本地代码上传到代码仓库,再从仓库拉取代码到本地。
新建镜像仓库
去docker官网https://hub.docker.com/注册个账号,新建仓库即可
操作过程类似github,这里就不再详解了
创建成功后,右侧会提示使用docker push推送
docker push ******/centos_jenkins:tagname
打本地标签tag
在上传之前,先给本地镜像打个tag标签,相当于重新复制镜像并重命名为docker账户名/仓库名称
docker tag 本地镜像:tag docker账号/docker仓库:tag
➜ ~ docker tag jenkins/jenkins:lts ******/centos_jenkins ➜ ~ docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins/jenkins lts e5599f396096 12 days ago 717MB ******/centos_jenkins latest e5599f396096 12 days ago 717MB
push 上传本地镜像
先使用命令docker login登陆docker hub账号
➜ ~ docker login Authenticating with existing credentials... Login Succeeded
上传本地镜像标签到镜像仓库,使用docker指令
docker push docker 账号/仓库名称:tagname
➜ ~ docker push s649821022/centos_jenkins Using default tag: latest The push refers to repository [docker.io/*******/centos_jenkins] b46a62d52dda: Mounted from jenkins/jenkins 4e0be38f7490: Mounted from jenkins/jenkins 0cd072c0ce42: Mounted from jenkins/jenkins 43fcd918f136: Mounted from jenkins/jenkins 21f11e7c3a56: Mounted from jenkins/jenkins eb36f7433291: Mounted from jenkins/jenkins 518a16e913d2: Mounted from jenkins/jenkins b25fdacd2517: Mounted from jenkins/jenkins bf63a4d81a68: Mounted from jenkins/jenkins 04ca868b414a: Mounted from jenkins/jenkins 7bbef5c83873: Mounted from jenkins/jenkins 21d861a860f6: Mounted from jenkins/jenkins ae2a8013d5a5: Mounted from jenkins/jenkins d81d8fa6dfd4: Mounted from jenkins/jenkins bd76253da83a: Mounted from jenkins/jenkins e43c0c41b833: Mounted from jenkins/jenkins 01727b1a72df: Pushed 69dfa7bd7a92: Mounted from jenkins/jenkins 4d1ab3827f6b: Mounted from jenkins/jenkins 7948c3e5790c: Mounted from jenkins/jenkins latest: digest: sha256:63fde6791bc9e11dc8fc94830ac76228afbe8d31206ab8f83f251314a3f45ba9 size: 4509
上传完成后打开自己的docker hub账号,查看镜像仓库
pull 拉取镜像
拉取镜像使用docker pull 你自己的镜像名称
docker pull ******/centos_jenkins