一、harbor推送镜像

1. 配置推送docker

将配置文件:/etc/docker/daemon.json

配置成:

{   "registry-mirrors": ["https://k1ktap5m.mirror.aliyuncs.com"],   "insecure-registries": ["http://43.154.32.5"] } 然后执行 systemctl daemon-reload systemctl restart docker

insecure-registries配置就是a机器的镜像源地址,注意,不可省略http和80端口(这个端口就是harbor.yml上配置的http端口),不然就会推送失败

2. 推送

  • 2.1 准备

先拉取一个镜像下来做试验用:

docker pull nginx

  • 2.2 标记镜像

       给待推送的镜像打标记,打标记命令格式如下:

docker tag SOURCE_IMAGE[:TAG] 43.154.32.5:80/library/REPOSITORY[:TAG]

   SOURCE_IMAGE[:TAG]表示当前docker已存在的某个版本的镜像

   library表示的是harbor里头的某个项目名称,表示镜像推送给这个项目

   注意,其中ip和端口都不要省(尤其在http协议里头)

   比如我要推送nginx到harbor仓库,打的标记如下:

docker tag nginx:latest 43.154.32.5:80/study/nginx:latest

  • 2.3 登录docker

    执行以下命令   

docker login 43.154.32.5:80

   登出docker的命令:

docker logout

登录成功

[root@VM-0-4-centos ~]# docker login 43.154.32.5:80 Username: xumeiqiang Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@VM-0-4-centos ~]#

  • 2.4 推送镜像

    推送命令:

docker push 43.154.32.5:80/study/nginx:latest

   docker push后面的其实就是打标记的时候标记。

   比如我要推送上面已经打好标记的镜像,命令如下:

docker push 43.154.32.5:80/library/nginx:latest

    推送日志

[root@VM-0-4-centos ~]# docker push 43.154.32.5:80/study/nginx:latest The push refers to repository [43.154.32.5:80/study/nginx] abc66ad258e9: Pushed 243243243ee2: Pushed f931b78377da: Pushed d7783033d823: Pushed 4553dc754574: Pushed 43b3c4e3001c: Pushed latest: digest: sha256:186c79dc14ab93e43d315143ee4b0774506dc4fd952388c20e35d3d37058ab8d size: 1570 [root@VM-0-4-centos ~]#

  • 2.5 查看