docker搭建私有仓库-08

一、docker搭建私有仓库

1.1、获取registry镜像

[root@docker-node1 ~]#docker pull registry
[root@docker-node1 ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
nulige/my_nginx             v2                  2a506435e91e        4 days ago          796 MB
docker.io/nulige/my_nginx   latest              b73ba52bdac7        4 days ago          796 MB
docker.io/nulige/nginx      latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx             latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx             v1                  b73ba52bdac7        4 days ago          796 MB
docker.io/nginx             latest              cd5239a0906a        2 weeks ago         109 MB
docker.io/centos            latest              49f7960eb7e4        2 weeks ago         200 MB
docker.io/registry          latest              d1fd7d86a825        5 months ago        33.3 MB
docker.io/alpine            latest              3fd9065eaf02        5 months ago        4.15 MB

1.2、创建用户和密码

[root@docker-node1 ~]# cd /opt/

[root@docker-node1 opt]# mkdir auth
[root@docker-node1 opt]# ls
aaa  auth  docker_test

#创建用户和密码  user:nulige passwd:123456
[root@docker-node1 opt]# docker run --entrypoint htpasswd registry:2 -Bbn nulige 123456 >auth/htpasswd
Unable to find image 'registry:2' locally
Trying to pull repository docker.io/library/registry ... 
2: Pulling from docker.io/library/registry
Digest: sha256:672d519d7fd7bbc7a448d17956ebeefe225d5eb27509d8dc5ce67ecb4a0bce54
Status: Downloaded newer image for docker.io/registry:2

[root@docker-node1 opt]# ls
aaa  auth  docker_test
[root@docker-node1 opt]# cat auth/htpasswd 
nulige:$2y$05$98P/LH7lC8FVc93nQwEJteZOl8eAHxEidNaBZeStt39emnTE3s46m

1.3、启动registry1容器 ,默认端口5000映射到6000

docker run  -d -p 6000:5000 --restart=always --name registry1 \
     -v `pwd`/auth:/auth \
     -e "REGISTRY_AUTH=htpasswd" \
     -e  "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
     -e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
     registry

#执行效果:

[root@docker-node1 opt]# docker run  -d -p 6000:5000 --restart=always --name registry1 \
>      -v `pwd`/auth:/auth \
>      -e "REGISTRY_AUTH=htpasswd" \
>      -e  "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
>      -e  REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
>      registry
9f93f17e06027f5e0845defed394c5348cb310a1900799347e10e21f6cf11141

1.4、访问registry仓库

[root@docker-node1 opt]# docker login 127.0.0.1:6000
Username: nulige
Password: 
Login Succeeded

1.5、打tag,上传镜像

[root@docker-node1 opt]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
nulige/my_nginx             v2                  2a506435e91e        4 days ago          796 MB
docker.io/nulige/my_nginx   latest              b73ba52bdac7        4 days ago          796 MB
docker.io/nulige/nginx      latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx             latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx             v1                  b73ba52bdac7        4 days ago          796 MB
docker.io/nginx             latest              cd5239a0906a        2 weeks ago         109 MB
docker.io/centos            latest              49f7960eb7e4        2 weeks ago         200 MB
docker.io/registry          2                   d1fd7d86a825        5 months ago        33.3 MB
docker.io/registry          latest              d1fd7d86a825        5 months ago        33.3 MB
docker.io/alpine            latest              3fd9065eaf02        5 months ago        4.15 MB

#打tag
[root@docker-node1 opt]# docker tag 2a506435e91e 127.0.0.1:6000/nulige/nginx

#上传镜像
[root@docker-node1 opt]# docker push 127.0.0.1:6000/nulige/nginx
The push refers to a repository [127.0.0.1:6000/nulige/nginx]
a27304149ecb: Pushed 
bcc97fbfc9e1: Pushed 
latest: digest: sha256:396ba6acbfcaeb2550b8eba0d386308af8fd59918cbd6bee734676409f2d1571 size: 742

1.6、同时删除多个镜像[root@docker-node1 opt]# docker images

REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
127.0.0.1                     6000                2a506435e91e        4 days ago          796 MB
127.0.0.1:6000/nulige/nginx   latest              2a506435e91e        4 days ago          796 MB
nulige/my_nginx               v2                  2a506435e91e        4 days ago          796 MB
docker.io/nulige/my_nginx     latest              b73ba52bdac7        4 days ago          796 MB
docker.io/nulige/nginx        latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx               latest              b73ba52bdac7        4 days ago          796 MB
nulige/my_nginx               v1                  b73ba52bdac7        4 days ago          796 MB
docker.io/nginx               latest              cd5239a0906a        2 weeks ago         109 MB
docker.io/centos              latest              49f7960eb7e4        2 weeks ago         200 MB
docker.io/registry            2                   d1fd7d86a825        5 months ago        33.3 MB
docker.io/registry            latest              d1fd7d86a825        5 months ago        33.3 MB
docker.io/alpine              latest              3fd9065eaf02        5 months ago        4.15 MB

[root@docker-node1 opt]# docker rmi -f 2a506435e91e 2a506435e91e 2a506435e91e b73ba52bdac7 Untagged: 127.0.0.1:6000 Untagged: 127.0.0.1:6000/nulige/nginx:latest Untagged: 127.0.0.1:6000/nulige/nginx@sha256:396ba6acbfcaeb2550b8eba0d386308af8fd59918cbd6bee734676409f2d1571 Untagged: nulige/my_nginx:v2 Deleted: sha256:2a506435e91e6803a9b156fda5a6ca5e217d8aa4cb9bc5bcabe753c3b15bc232 Untagged: docker.io/nulige/my_nginx:latest Untagged: docker.io/nulige/nginx:latest Untagged: nulige/my_nginx:latest Untagged: nulige/my_nginx:v1 Deleted: sha256:b73ba52bdac7747864966afcf7c8c671cbea79537f2bcca04648411685802177 Deleted: sha256:01a8429e9d56d5a5d2472cc0e4215b3c6eb55208069eafb386efa60282085cbc Error response from daemon: No such image: 2a506435e91e:latest Error response from daemon: No such image: 2a506435e91e:latest
[root@docker-node1 opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest cd5239a0906a 2 weeks ago 109 MB docker.io/centos latest 49f7960eb7e4 2 weeks ago 200 MB docker.io/registry 2 d1fd7d86a825 5 months ago 33.3 MB docker.io/registry latest d1fd7d86a825 5 months ago 33.3 MB docker.io/alpine latest 3fd9065eaf02 5 months ago 4.15 MB

1.7、从自已搭的私有仓库下载镜像

#下载nginx镜像
[root@docker-node1 opt]# docker pull 127.0.0.1:6000/nulige/nginx Using default tag: latest Trying to pull repository 127.0.0.1:6000/nulige/nginx ... latest: Pulling from 127.0.0.1:6000/nulige/nginx 7dc0dca2b151: Already exists a827ace00187: Pull complete Digest: sha256:396ba6acbfcaeb2550b8eba0d386308af8fd59918cbd6bee734676409f2d1571 Status: Downloaded newer image for 127.0.0.1:6000/nulige/nginx:latest
#查看所有镜像,看是否有nulige/nginx镜像
[root@docker-node1 opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 127.0.0.1:6000/nulige/nginx latest 2a506435e91e 4 days ago 796 MB docker.io/nginx latest cd5239a0906a 2 weeks ago 109 MB docker.io/centos latest 49f7960eb7e4 2 weeks ago 200 MB docker.io/registry 2 d1fd7d86a825 5 months ago 33.3 MB docker.io/registry latest d1fd7d86a825 5 months ago 33.3 MB docker.io/alpine latest 3fd9065eaf02 5 months ago 4.15 MB [root@docker-node1 opt]#

1.8、问题解决

[root@docker-node2 ~]# docker login 192.168.0.26
Username: nulige
Password: 
Error response from daemon: Get https://192.168.0.26/v1/users/: dial tcp 192.168.0.26:443: getsockopt: connection refused

 加上参数:

 

posted @ 2018-06-21 20:41  努力哥  阅读(238)  评论(0编辑  收藏  举报