第二步:私有镜像仓库Harbor的使用

前序:
        第一步:私有镜像仓库Harbor的安装部署

一、将容器打包为镜像,上传到Harbor

1、查看镜像

输入命令

docker images

打印返回

REPOSITORY                             TAG       IMAGE ID       CREATED        SIZE
ubuntu                                 16.04     b6f507652425   2 years ago    135MB

2、查看容器

输入命令

docker ps -a

打印返回

CONTAINER ID   IMAGE          COMMAND   CREATED      STATUS                    PORTS                                   NAMES
e80c30a2e599   ubuntu:16.04   "bash"    7 days ago   Exited (0) 18 hours ago   0.0.0.0:8801->80/tcp, :::8801->80/tcp   ubuntu-1

1、打包容器

docker commit -a "lxcw"  -m "for vAC keepalived+nginx" ubuntu-1 vac_ubuntu:v0.1

2、查看镜像

输入命令

docker images

打印返回

REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
vac_ubuntu                              v0.1      b1e07b814206   23 hours ago   444MB
ubuntu                                  16.04     b6f507652425   2 years ago    135MB

3、标记镜像

 docker tag vac_ubuntu:v0.1 192.168.100.120:8802/library/vac_ubuntu:v0.1

4、查看镜像

输入命令

docker images

打印返回

REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
vac_ubuntu                              v0.1      b1e07b814206   23 hours ago   444MB
192.168.100.120:8802/library/vac_ubuntu v0.1      b1e07b814206   23 hours ago   444MB
ubuntu                                  16.04     b6f507652425   2 years ago    135MB

2、登录仓库

docker login -u admin -p Harbor12345 192.168.100.120:8802

2、上传镜像

输入命令

docker push 192.168.100.120:8802/library/vac_ubuntu:v0.1

打印返回

The push refers to repository [192.168.100.120:8802/library/vac_ubuntu]
fedb7970623a: Pushed 
1251204ef8fc: Pushed 
47ef83afae74: Pushed 
df54c846128d: Pushed 
be96a3f634de: Pushed 

二、从Harbor拉取镜像到本地

1、查看本地已存在镜像

docker images
REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
vac_ubuntu                              v0.1      b1e07b814206   23 hours ago   444MB
192.168.100.120:8802/library/vac_ubuntu v0.1      b1e07b814206   23 hours ago   444MB
ubuntu                                  16.04     b6f507652425   2 years ago    135MB

2、已存在,先删除

docker rmi 192.168.100.120:8802/library/vac_ubuntu:v0.1

3、查看镜像

输入命令

 docker images

打印返回

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
vac_ubuntu   v0.1      b1e07b814206   24 hours ago   444MB
ubuntu       16.04     b6f507652425   2 years ago    135MB

3、拉取镜像

docker pull 192.168.100.120:8802/library/vac_ubuntu:v0.1

4、查看镜像

输入命令

docker images

打印返回

REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
192.168.100.120:8802/library/vac_ubuntu v0.1      b1e07b814206   24 hours ago   444MB
vac_ubuntu                              v0.1      b1e07b814206   24 hours ago   444MB
ubuntu                                  16.04     b6f507652425   2 years ago    135MB

三、一些问题?

1、connect: no route to host

问题重现

The push refers to repository [192.168.100.120:8802/library/vac_ubuntu]
Get "http://192.168.100.120:8802/v2/": dial tcp 192.168.100.120:8802: connect: no route to host
原因: 防火墙未允许8802端口通过,关闭Harbor仓库所在主机的防火墙,或者打开8802端口规则
解决方法: 关闭防火墙

输入命令

systemctl stop firewalld

2、connect: connection refused

问题重现

Error response from daemon: Get "http://192.168.100.120:8802/v2/": dial tcp 192.168.100.120:8802: connect: connection refused
原因: docker客户端未添加白名单,即忽略安全注册表
解决方法: 如下

输入命令

vim /etc/docker/daemon.json

增加内容

{
	"insecure-registries": ["192.168.100.120:8802"]
}

重启守护进程

systemctl daemon-reload

重启docker

systemctl restart docker

测试登录

docker login -u admin -p Harbor12345 192.168.100.120:8802

你可能感兴趣的:(#,Docker,docker,ubuntu,服务器)