Docker私有仓库管理和删除本地仓库中的镜像

2020-06-17 06:39:34易采站长站整理

一:Docker私有仓库安装

1、 下载镜像是有镜像仓库:


[root@localhost ~]# systemctl start docker

#如果已经有镜像了,强制删除原来的镜像的方式如下:
[root@xxx-pub /]# docker rmi -f docker.io/registry
Untagged: docker.io/registry:latest
Untagged: docker.io/registry@sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
[root@xxx-pub /]#

#开始下载最新的镜像。
[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
4064ffdc82fe: Pull complete
c12c92d1c5a2: Pull complete
4fbc9b6835cc: Pull complete
765973b0f65f: Pull complete
3968771a7c3a: Pull complete
Digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129
Status: Downloaded newer image for registry:latest
[root@localhost ~]#

2、 启动并且挂载镜像仓库到本地磁盘:


[root@xxx-pub /]# docker run -d -v /registry:/home/docker-registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest
Unable to find image 'registry:latest' locally
Trying to pull repository docker.io/library/registry ...
latest: Pulling from docker.io/library/registry
Digest: sha256:51bb55f23ef7e25ac9b8313b139a8dd45baa832943c8ad8f7da2ddad6355b3c8
Status: Downloaded newer image for docker.io/registry:latest
b7bd2b14ed488936afe798be95f3cd56f604fb092d45cf6f4a58359bcad0d34c
[root@xxx-pub /]#

-v /registry:/home/docker-registry:默认情况下,会将仓库存放于容器内的/home/docker-registry目录下,指定本地目录挂载到容器。
-p 5000:5000 :端口映射。即本地5000端口,映射到registry中的5000端口。
–restart=always1:在容器退出时总是重启容器,主要应用在生产环境。
–privileged=true:在CentOS7中的安全模块selinux把权限禁掉了,参数给容器加特权,不加上传镜像会报类似权限错误。OSError: [Errno 13] Permission denied: ‘/tmp/registry/repositories/liibrary’)或者(Received unexpected HTTP status: 500 Internal Server Error)
–name registry:指定容器的名称。

为了持久化数据,将volume挂载到/home/docker-registry

3、 我们给一个本地镜像打个标签然后上传:

查看本地有哪些镜像:


[root@xxx-pub /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos centos7.5.1804 fdf13fa91c6e 4 weeks ago 200 MB
docker.io/registry latest b2b03e9146e1 2 months ago 33.3 MB
[root@xxx-pub /]#

以docker.io/centos为案例。


[root@xxx-pub /]# docker tag fdf13fa91c6e localhost:5000/xxx-centos7.5.1804:1.0