搭建Docker镜像私有服务器

一 实战
服务端
[root@localhost opt]# docker run -d -p 5000:5000 -v /opt/docker/registry:/var/lib/registry --restart always --name registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
49388a8c9c86: Pull complete
e4d43608dd22: Pull complete
3a41740f900c: Pull complete
e16ef4b76684: Pull complete
65f212f7c778: Pull complete
Digest: sha256:6c891f9a234e44522652261029bd8ae5f7f4b5a0e9fae48986cd3b3fdbecc157
Status: Downloaded newer image for registry:2
f50c2252e2d2be9605083f8b7956817924c778dfb9146cbacf0da319d42b770e
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                    NAMES
f50c2252e2d2        registry:2          "/entrypoint.sh /e..."   3 minutes ago       Up 3 minutes            0.0.0.0:5000->5000/tcp   registry
bc87f94ee147        imageb              "/bin/bash"              3 days ago          Exited (0) 3 days ago                            test2
7d9c810d02e2        imagea              "/bin/bash"              3 days ago          Exited (0) 3 days ago                            test1
[root@localhost opt]# docker exec -it f5 /bin/sh
/ # cd /var/lib
/var/lib # cd registry/
/var/lib/registry # ls
docker
/var/lib/registry # cd docker/
/var/lib/registry/docker # ls
registry
/var/lib/registry/docker # cd registry/
/var/lib/registry/docker/registry # ls
v2
/var/lib/registry/docker/registry # cd v2
/var/lib/registry/docker/registry/v2 # ls
blobs         repositories
/var/lib/registry/docker/registry/v2 # cd repositories/
/var/lib/registry/docker/registry/v2/repositories # ls
vker
/var/lib/registry/docker/registry/v2/repositories # cd vker/
/var/lib/registry/docker/registry/v2/repositories/vker # ls
box
/var/lib/registry/docker/registry/v2/repositories/vker # cd box/
/var/lib/registry/docker/registry/v2/repositories/vker/box # ls
_layers     _manifests  _uploads
/var/lib/registry/docker/registry/v2/repositories/vker/box # exit
[root@localhost opt]# cd /opt/docker/registry
[root@localhost registry]# ls
docker
[root@localhost registry]# cd docker/
[root@localhost docker]# ls
registry
[root@localhost docker]# cd registry/
[root@localhost registry]# ls
v2
[root@localhost registry]# cd v2/
[root@localhost v2]# ls
blobs  repositories
[root@localhost v2]# cd repositories/
[root@localhost repositories]# ls
vker
[root@localhost repositories]# cd vker/
[root@localhost vker]# ls
box
[root@localhost vker]# cd box
[root@localhost box]# ls
_layers  _manifests  _uploads
客户端
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tomcat              latest              11df4b40749f        20 hours ago        557MB
imageb              latest              5c2c5afb166f        3 days ago          62.5MB
imagea              latest              21a1a8062b5f        3 days ago          62.5MB
clearlinux          latest              32685d114002        11 days ago         62.5MB
busybox             latest              6ad733544a63        11 days ago         1.13MB
registry            2                   a07e3f32a779        11 days ago         33.3MB
alpine              latest              053cde6e8953        11 days ago         3.96MB
[root@localhost ~]# docker tag busybox:latest 192.168.0.107:5000/vker/box:0.1
[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
tomcat                        latest              11df4b40749f        20 hours ago        557MB
imageb                        latest              5c2c5afb166f        3 days ago          62.5MB
imagea                        latest              21a1a8062b5f        3 days ago          62.5MB
clearlinux                    latest              32685d114002        11 days ago         62.5MB
192.168.0.107:5000/vker/box   0.1                 6ad733544a63        11 days ago         1.13MB
busybox                       latest              6ad733544a63        11 days ago         1.13MB
registry                      2                   a07e3f32a779        11 days ago         33.3MB
alpine                        latest              053cde6e8953        11 days ago         3.96MB
[root@localhost ~]# docker push 192.168.0.107:5000/vker/box:0.1
The push refers to a repository [192.168.0.107:5000/vker/box]
Get https://192.168.0.107:5000/v2/: http: server gave HTTP response to HTTPS client
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cd /etc/docker
[root@localhost docker]# ls
key.json
[root@localhost docker]# vi daemon.json
[root@localhost docker]# cat daemon.json
{
        "insecure-registries": ["192.168.0.107:5000"]
}
[root@localhost docker]# systemctl restart docker
[root@localhost docker]# docker push 192.168.0.107:5000/vker/box:0.1
The push refers to a repository [192.168.0.107:5000/vker/box]
0271b8eebde3: Pushed
0.1: digest: sha256:91ef6c1c52b166be02645b8efee30d1ee65362024f7da41c404681561734c465 size: 527
[root@localhost docker]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
tomcat                        latest              11df4b40749f        20 hours ago        557MB
imageb                        latest              5c2c5afb166f        3 days ago          62.5MB
imagea                        latest              21a1a8062b5f        3 days ago          62.5MB
clearlinux                    latest              32685d114002        11 days ago         62.5MB
192.168.0.107:5000/vker/box   0.1                 6ad733544a63        11 days ago         1.13MB
busybox                       latest              6ad733544a63        11 days ago         1.13MB
registry                      2                   a07e3f32a779        11 days ago         33.3MB
alpine                        latest              053cde6e8953        11 days ago         3.96MB
[root@localhost docker]# docker rmi 192.168.0.107:5000/vker/box:0.1
Untagged: 192.168.0.107:5000/vker/box:0.1
Untagged: 192.168.0.107:5000/vker/box@sha256:91ef6c1c52b166be02645b8efee30d1ee65362024f7da41c404681561734c465
[root@localhost docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
tomcat              latest              11df4b40749f        20 hours ago        557MB
imageb              latest              5c2c5afb166f        3 days ago          62.5MB
imagea              latest              21a1a8062b5f        3 days ago          62.5MB
clearlinux          latest              32685d114002        11 days ago         62.5MB
busybox             latest              6ad733544a63        11 days ago         1.13MB
registry            2                   a07e3f32a779        11 days ago         33.3MB
alpine              latest              053cde6e8953        11 days ago         3.96MB
[root@localhost docker]# docker pull 192.168.0.107:5000/vker/box:0.1
0.1: Pulling from vker/box
Digest: sha256:91ef6c1c52b166be02645b8efee30d1ee65362024f7da41c404681561734c465
Status: Downloaded newer image for 192.168.0.107:5000/vker/box:0.1
[root@localhost docker]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
tomcat                        latest              11df4b40749f        20 hours ago        557MB
imageb                        latest              5c2c5afb166f        3 days ago          62.5MB
imagea                        latest              21a1a8062b5f        3 days ago          62.5MB
clearlinux                    latest              32685d114002        11 days ago         62.5MB
192.168.0.107:5000/vker/box   0.1                 6ad733544a63        11 days ago         1.13MB
busybox                       latest              6ad733544a63        11 days ago         1.13MB
registry                      2                   a07e3f32a779        11 days ago         33.3MB

alpine                        latest              053cde6e8953        11 days ago         3.96MB


你可能感兴趣的:(Docker)