Docker 私有仓库Harbor推拉镜像(二)
· 技术积累 · Centos7 Docker Harbor

接上篇文章继续
上篇博文写了:Harbor安装配置
此篇写下Harbor的 使用http协议,镜像推送和拉取

1、docker客户端修改docker.service配置文件

# 确认下docker的版本
docker version
Client:
 Version:           18.09.1-beta2
 API version:       1.39
 Go version:        go1.10.5
 Git commit:        74239bf
 Built:             Tue Dec  4 01:08:56 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1-beta2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.5
  Git commit:       74239bf
  Built:            Tue Dec  4 00:33:49 2018
  OS/Arch:          linux/amd64
  Experimental:     false

# 修改docker.service 服务启动文件,加上harbor镜像仓库地址
······
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --graph /data/docker --insecure-registry=192.168.16.215
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
······

# 重新加载docker服务
systemctl daemon-reload
systemctl restart docker

# 查看是否生效
ps -ef|grep docker

Docker 私有仓库Harbor推拉镜像(二)


2、web界面创建一个新的项目和用户用来测试镜像推送和拉取

Docker 私有仓库Harbor推拉镜像(二)

Docker 私有仓库Harbor推拉镜像(二)

Docker 私有仓库Harbor推拉镜像(二)


3、客户端登录harbor镜像仓库,并推送一个镜像

[root@localhost ~]# docker login -ujc -padminADMIN1 192.168.16.215
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
8559a31e96f4: Pull complete 
1cf27aa8120b: Pull complete 
67d252a8c1e1: Pull complete 
9c2b660fcff6: Pull complete 
4584011f2cd1: Pull complete 
Digest: sha256:a93c8a0b0974c967aebe868a186e5c205f4d3bcb5423a56559f2f9599074bbcd
Status: Downloaded newer image for nginx:latest

[root@localhost ~]# docker tag nginx 192.168.16.215/jctest/nginx

[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
192.168.16.215/jctest/nginx   latest              0901fa9da894        4 days ago          132MB
nginx                         latest              0901fa9da894        4 days ago          132MB

[root@localhost ~]# docker push 192.168.16.215/jctest/nginx
The push refers to repository [192.168.16.215/jctest/nginx]
2808ec4a8ea7: Pushed 
4856db5e4f59: Pushed 
7ef35766ef7d: Pushed 
0e32546a8af0: Pushed 
13cb14c2acd3: Pushed 
latest: digest: sha256:8ff4598873f588ca9d2bf1be51bdb117ec8f56cdfd5a81b5bb0224a61565aa49 size: 1362
[root@localhost ~]# 

Docker 私有仓库Harbor推拉镜像(二)

Docker 私有仓库Harbor推拉镜像(二)


4、客户端从私有镜像仓库拉取一个镜像

[root@localhost ~]# docker login -ujc -padminADMIN1 192.168.16.215
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
192.168.16.215/jctest/nginx   latest              0901fa9da894        4 days ago          132MB
nginx                         latest              0901fa9da894        4 days ago          132MB

# 删除本地镜像仓库的镜像
[root@localhost ~]# docker rmi 192.168.16.215/jctest/nginx
Untagged: 192.168.16.215/jctest/nginx:latest
Untagged: 192.168.16.215/jctest/nginx@sha256:8ff4598873f588ca9d2bf1be51bdb117ec8f56cdfd5a81b5bb0224a61565aa49
[root@localhost ~]# docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:a93c8a0b0974c967aebe868a186e5c205f4d3bcb5423a56559f2f9599074bbcd
Deleted: sha256:0901fa9da894a8e9de5cb26d6749eaffb67b373dc1ff8a26c46b23b1175c913a
Deleted: sha256:89a4b5ca03d8301855dee414fc0631cff6410a48ff3a54f5f271906b81cd4e2b
Deleted: sha256:2e03e0e054440102d46743deb10a98bd4a2da37282a5c955c65e30a7bca53fc7
Deleted: sha256:f7b1f49be3e1a298b598c7822a2a9334e0b806da2da34a740a4d64b7c5f877ce
Deleted: sha256:2cdd3840848b3193bc22db56d42a6debdee858468fe3b506656d7d3c836a23c7
Deleted: sha256:13cb14c2acd34e45446a50af25cb05095a17624678dbafbcc9e26086547c1d74

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

# 从harbor私有镜像仓库拉取之前上传的镜像
[root@localhost ~]# docker pull 192.168.16.215/jctest/nginx
Using default tag: latest
latest: Pulling from jctest/nginx
8559a31e96f4: Pull complete 
1cf27aa8120b: Pull complete 
67d252a8c1e1: Pull complete 
9c2b660fcff6: Pull complete 
4584011f2cd1: Pull complete 
Digest: sha256:8ff4598873f588ca9d2bf1be51bdb117ec8f56cdfd5a81b5bb0224a61565aa49
Status: Downloaded newer image for 192.168.16.215/jctest/nginx:latest

[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
192.168.16.215/jctest/nginx   latest              0901fa9da894        4 days ago          132MB

[root@localhost ~]# date 
Wed Jul 15 11:41:37 CST 2020

5、web控制台可以看到拉取镜像的记录

Docker 私有仓库Harbor推拉镜像(二)


本文最后更新时间 2020-07-15
文章链接地址:
https://me.jinchuang.org/archives/657.html
本站文章除注明[转载|引用|原文]出处外,均为本站原生内容,转载前请注明出处


留言