Docker私有仓库Harbor使用操作

只愿长相守 提交于 2020-03-15 15:28:38

Harbor页面基础操作

1):网页登陆http://192.168.100.61/

默认账户密码:admin  Harbor12345
[root@localhost ~]# cat /data/harbor/harbor.cfg | grep harbor_admin_password

2):用户管理

系统管理--用户管理--创建用户

3):新建一个项目

4):上传下载镜像到Harbor仓库

[root@localhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   docker2
[root@localhost ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.100.61:5000"],
  "insecure-registries": ["docker2:80"]
}
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

# 把要上传的镜像打上合适的标签
[root@localhost ~]# docker tag busybox:latest docker2:80/demo/busybox:v0.1
[root@localhost ~]# docker tag nginx:1.14-alpine docker2:80/demo/nginx:v0.1
[root@localhost ~]# docker tag nginx:1.14 docker2:80/demo/nginx:v0.2
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
docker2:80/demo/busybox         v0.1                83aa35aa1c79        5 days ago          1.22MB
docker2:80/demo/nginx           v0.1                8a2fb25a19f5        11 months ago       16MB
docker2:80/demo/nginx           v0.2                295c7be07902        11 months ago       109MB

# 登录harbor仓库
[root@localhost ~]# docker login docker2:80
Username: admin
Password:
Login Succeeded

# 上传镜像
[root@localhost ~]# docker push docker2:80/demo/busybox:v0.1
The push refers to repository [docker2:80/demo/busybox]
a6d503001157: Pushed
v0.1: digest: sha256:afe605d272837ce1732f390966166c2afff5391208ddd57de10942748694049d size: 527
# 如果不知道tag,会把这个镜像的所有tag都上传
[root@localhost ~]# docker push docker2:80/demo/nginx
The push refers to repository [docker2:80/demo/nginx]
076c58d2644f: Pushed
b2cbae4b8c15: Pushed
5ac9a5170bf2: Pushed
a464c54f93a9: Pushed
v0.1: digest: sha256:a3a0c4126587884f8d3090efca87f5af075d7e7ac8308cffc09a5a082d5f4760 size: 1153
82ae01d5004e: Pushed
b8f18c3b860b: Pushed
5dacd731af1b: Pushed
v0.2: digest: sha256:706446e9c6667c0880d5da3f39c09a6c7d2114f5a5d6b74a2fafd24ae30d2078 size: 948

5):再harbor上验证上传成功

6):拉取harbor中的镜像

# 删除镜像
[root@localhost ~]# docker rmi docker2:80/demo/nginx:v0.1
Untagged: docker2:80/demo/nginx:v0.1
Untagged: docker2:80/demo/nginx@sha256:a3a0c4126587884f8d3090efca87f5af075d7e7ac8308cffc09a5a082d5f4760
[root@localhost ~]# docker rmi docker2:80/demo/nginx:v0.2
Untagged: docker2:80/demo/nginx:v0.2
Untagged: docker2:80/demo/nginx@sha256:706446e9c6667c0880d5da3f39c09a6c7d2114f5a5d6b74a2fafd24ae30d2078
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE

# 拉取镜像
[root@localhost ~]# docker pull docker2:80/demo/busybox:v0.1
v0.1: Pulling from demo/busybox
Digest: sha256:afe605d272837ce1732f390966166c2afff5391208ddd57de10942748694049d
Status: Downloaded newer image for docker2:80/demo/busybox:v0.1
docker2:80/demo/busybox:v0.1
[root@localhost ~]# docker pull docker2:80/demo/nginx:v0.1
v0.1: Pulling from demo/nginx
Digest: sha256:a3a0c4126587884f8d3090efca87f5af075d7e7ac8308cffc09a5a082d5f4760
Status: Downloaded newer image for docker2:80/demo/nginx:v0.1
docker2:80/demo/nginx:v0.1
[root@localhost ~]# docker pull docker2:80/demo/nginx:v0.2
v0.2: Pulling from demo/nginx
Digest: sha256:706446e9c6667c0880d5da3f39c09a6c7d2114f5a5d6b74a2fafd24ae30d2078
Status: Downloaded newer image for docker2:80/demo/nginx:v0.2
docker2:80/demo/nginx:v0.2
[root@localhost ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
docker2:80/demo/busybox         v0.1                83aa35aa1c79        5 days ago          1.22MB
docker2:80/demo/nginx           v0.1                8a2fb25a19f5        11 months ago       16MB
docker2:80/demo/nginx           v0.2                295c7be07902        11 months ago       109MB

7):在harbor web页面可以进行很多实用的操作

如:给镜像打标签、复制镜像、删除镜像等;

8):控制harbor服务

[root@localhost ~]# cd /data/harbor/
# 通过docker-compose命令对harbor进行控制
# 暂停harbor服务
[root@localhost harbor]# docker-compose pause
Pausing harbor-log         ... done
Pausing registry           ... done
Pausing harbor-adminserver ... done
Pausing harbor-db          ... done
Pausing redis              ... done
Pausing harbor-core        ... done
Pausing harbor-portal      ... done
Pausing nginx              ... done

# 停止harbor服务
[root@localhost harbor]# docker-compose stop
Stopping nginx              ... done
Stopping harbor-portal      ... done
Stopping harbor-core        ... done
Stopping redis              ... done
Stopping harbor-db          ... done
Stopping harbor-adminserver ... done
Stopping registry           ... done
Stopping harbor-log         ... done

# 开启harbor服务
[root@localhost harbor]# docker-compose start
Starting log         ... done
Starting registry    ... done
Starting registryctl ... done
Starting postgresql  ... done
Starting adminserver ... done
Starting core        ... done
Starting portal      ... done
Starting redis       ... done
Starting jobservice  ... done
Starting proxy       ... done
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!