安装docker 参见以前文章
私有仓库的搭建
1:下载registry镜像
docker pull registry
2:通过该镜像启动容器
docker run -d -p 5000:5000 registry
默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下,如下:
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
3:测试push到该仓库
下载nginx镜像
docker pull nginx
修改tag
doker tag nginx 10.1.4.54:5000/nginx
上传到仓库
doker push 10.1.4.54:5000/nginx
但是遇到了错误
[root@10-1-4-88 ~]# docker push 10.1.4.54:5000/nginx
The push refers to a repository [10.1.4.54:5000/nginx]
Get https://10.1.4.54:5000/v2/: http: server gave HTTP response to HTTPS client
解决办法:
[root@10-1-4-88 ~]# vi /etc/docker/daemon.json
{ "insecure-registries":["10.1.4.54:5000"] }
重起服务
[root@10-1-4-88 ~]# systemctl restart docker
在次提交
[root@10-1-4-88 ~]# docker push 10.1.4.54:5000/nginx
The push refers to a repository [10.1.4.54:5000/nginx]
54b25ecf81f0: Pushed
110566462efa: Pushed
305e2b6ef454: Pushed
24e065a5f328: Pushed
latest: digest: sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f size: 1155
4:查询私有仓库镜像
docker search 10.1.4.54:5000/
遇到错误
[root@10-1-4-88 ~]# docker search 10.1.4.54:5000/
Error response from daemon: Unexpected status code 404
查看下来不能使用docker search
解决办法:
但是通过v2 的api 可以实现相同的目的
[root@10-1-4-88 ~]# curl http://10.1.4.54:5000/v2/_catalog
{"repositories":["nginx"]}
[root@10-1-4-88 ~]# curl http://10.1.4.54:5000/v2/nginx/tags/list
{"name":"nginx","tags":["latest"]}
5:删除本地镜像在从私有仓库下载 pull
查询本地images
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.1.4.54:5000/nginx latest 1628545933ab About an hour ago 108MB
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
删除10.1.4.54:5000/nginx
[root@10-1-4-88 ~]# docker rmi 10.1.4.54:5000/nginx
Untagged: 10.1.4.54:5000/nginx:latest
Untagged: 10.1.4.54:5000/nginx@sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f
再次查询本地images
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
从私有仓库下载镜像10.1.4.54:5000
[root@10-1-4-88 ~]# docker pull 10.1.4.54:5000/nginx
Using default tag: latest
latest: Pulling from nginx
Digest: sha256:8f0365ebf863a78c72154bdc6af687c5c78221cf9b15ee6a0cab9a935405b38f
Status: Downloaded newer image for 10.1.4.54:5000/nginx:latest
再次查看镜像
[root@10-1-4-88 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.1.4.54:5000/nginx latest 1628545933ab About an hour ago 108MB
nginx latest 1628545933ab About an hour ago 108MB
<none> <none> 1717b3a9873b About an hour ago 108MB
nginx <none> da5939581ac8 3 weeks ago 108MB
[root@10-1-4-88 ~]#