Harbor安装和镜像推送

发布时间 2023-10-23 11:31:58作者: 蕝戀

安装前提:

yum -y install docker-compose-plugin

安装:

tar -zxvf harbor-offline-installer-v2.6.1.tgz

cd harbor
cp harbor.yml.tmpl harbor.yml

vim harbor.yml

修改hostname为主机IP地址
注解掉https的配置。除非你打算用,那就把证书和私钥准备好。

运行 ./install

harbor默认是80端口。


启动/停止

cd /harbor

docker-compose stop
docker-compose up -d


推送到harbor仓库:


# 登陆镜像仓库
Usage:  docker login [OPTIONS] [SERVER]

Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.

Options:
  -p, --password string   Password
      --password-stdin    Take the password from stdin
  -u, --username string   Username


# 打标签
docker tag [ImageId] [镜像仓库地址]:[镜像版本号]
    如:docker tag SOURCE_IMAGE[:TAG] 10.0.1.140/library/REPOSITORY[:TAG]

# 推送镜像
docker push [镜像仓库地址]:[镜像版本号]
  如:docker push 10.0.1.140/library/REPOSITORY[:TAG]

实例:

# 登陆镜像仓库
[root@k8s-master ~]# docker login -p harbor 10.0.1.140
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Username: admin
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@k8s-master ~]# docker tag nginx 10.0.1.140/library/mynginx:v2

# 查看镜像,看看是否打了标记
[root@k8s-master ~]# docker images
REPOSITORY                                                        TAG       IMAGE ID       CREATED         SIZE
nginx                                                             latest    605c77e624dd   9 months ago    141MB
10.0.1.140/library/mynginx                                        v2        605c77e624dd   9 months ago    141MB  # 这个是我们刚打的TAG镜像

#推送镜像,我这里提示已经存在是因为之前推送过一模一样的,但是只是版本不一样。
[root@k8s-master ~]# docker push 10.0.1.140/library/mynginx:v2
The push refers to repository [10.0.1.140/library/mynginx]
d874fd2bc83b: Layer already exists
32ce5f6a5106: Layer already exists
f1db227348d0: Layer already exists
b8d6e692a25e: Layer already exists
e379e8aedd4d: Layer already exists
2edcec3590a4: Layer already exists
v2: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570


https:

按照官方教程即可,注意v3.ext文件,如果是就参考第三个连接,将alt_names选项中加入IP

[alt_names]
IP.1=192.168.2.6
# DNS.1=www.swq.com # 如果是用域名就写这个。

https://goharbor.io/docs/2.9.0/install-config/configure-https/#generate-a-certificate-authority-certificate