欢迎光临范阳布衣的运维博客
分享工作和学习中的知识、技术

docker-镜像仓库-registry

搭建私有镜像仓库

Docker Hub作为Docker默认官方公共镜像;如果想自己搭建私有镜像仓库,官方也提供registry镜像,使得搭建私有仓库非常简单。

下载registry镜像并启动

docker pull registry
docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry

例:

[root@docker ~]# mkdir /opt/registry
[root@docker ~]# docker container run -d --volume type=bind,src=/opt/registry,dst=/var/lib/registry -p 5000:5000 --name registry registry
716b8e537b8671b20c29b4570b0aa45f94a5c5eb52b6622c2cfd56a74f6526da
[root@docker ~]# docker container ps -a
CONTAINER IDIMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
716b8e537b86registry"/entrypoint.sh /etc…"7 seconds ago       Up 6 seconds        0.0.0.0:5000->5000/tcp   registry

测试,查看镜像仓库中所有镜像

[root@docker ~]# curl http://192.9.201.90:5000/v2/_catalog
{"repositories":[]}

私有镜像仓库管理

打标签

[root@docker ~]# docker tag nginx 192.9.201.90:5000/nginx:1.12
[root@docker ~]# docker image ls
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
192.9.201.90:5000/nginx   1.12                cd5239a0906a        3 weeks ago         109MB
nginx                     latest              cd5239a0906a        3 weeks ago         109MB

上传

[root@docker ~]# docker push 192.9.201.90:5000/nginx:1.12
The push refers to repository [192.9.201.90:5000/nginx]
Get https://192.9.201.90:5000/v2/: http: server gave HTTP response to HTTPS client
#报错,使用HTTPS请求

配置私有仓库可信任

[root@docker ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": [ "https://registry.docker-cn.com"],
  "insecure-registries":["192.9.201.90:5000"]
}

重启Docker

[root@docker ~]# systemctl reset-failed docker.service
[root@docker ~]# systemctl restart docker.service

再提交镜像

[root@docker ~]# docker push 192.9.201.90:5000/nginx:1.12
The push refers to repository [192.9.201.90:5000/nginx]
3ff93588120e: Pushed
24ee0a3fd4b9: Pushed
d626a8ad97a1: Pushed
1.12: digest: sha256:1f9c00b4c95ef931afa097823d902e7602aebc3ec5532e907e066978075ca3e0 size: 948

列出镜像标签

[root@docker ~]# curl http://192.9.201.90:5000/v2/_catalog
{"repositories":["nginx"]}

[root@docker ~]# curl http://192.9.201.90:5000/v2/nginx/tags/list
{"name":"nginx","tags":["1.12"]}

拉取镜像

[root@docker ~]# docker run -itd --name nginx -p 80:80 192.9.201.90:5000/nginx:1.12
Unable to find image '192.9.201.90:5000/nginx:1.12' locally
1.12: Pulling from nginx
f2aa67a397c4: Pull complete
1cd0975d4f45: Pull complete
72fd2d3be09a: Pull complete
Digest: sha256:1f9c00b4c95ef931afa097823d902e7602aebc3ec5532e907e066978075ca3e0
Status: Downloaded newer image for 192.9.201.90:5000/nginx:1.12
3df4e14af91f5ea122854af9fac312a87495f93bf893b3c7c30826254626ff69
[root@docker ~]# docker container  ps -a
CONTAINER IDIMAGECOMMANDCREATED             STATUS              PORTS                    NAMES
3df4e14af91f      192.9.201.90:5000/nginx:1.12   "nginx -g 'daemon of…"   7 seconds ago       Up 6 seconds        0.0.0.0:80->80/tcp       nginx

Docker Hub公共镜像仓库使用

注册账号

https://hub.docker.com

登录Docker Hub

docker login
或
docker login --username=xxxxxxxx --password=123456

镜像打标签

docker tag wordpress:v1 xxxxxx/wordpress:v1`

上传

docker push xxxxxx/wordpress:v1

搜索测试:

docker search xxxxxx

下载

docker pull xxxxxx/wordpress:v1
未经允许不得转载:范阳布衣 » docker-镜像仓库-registry