020、搭建本地Registry(2019-01-11 周五)
Docker Hub 虽然方便,但还是有些限制,比如
1、需要Internet连接,上传下载速度慢
2、上传到Docker Hub上的公共镜像任何人都能访问,私有Registry需要收费
3、出于安全原因很多公司不允许将镜像放到外网
最简单的解决方案就是搭建本地Registry(Registry也支持认证和https加密,这里不做讲解)
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
root@docker-lab:~/020# docker build -t test020 . # 构建一个用于测试上传下载的镜像
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM busybox
latest: Pulling from library/busybox
57c14dd66db0: Pull complete
Digest: sha256:b6e640a3768c460ad6066a003b6da52034c31aaf8500f9263057ddffcd830ef6
Status: Downloaded newer image for busybox:latest
---> 3a093384ac30
Step 2/2 : CMD echo "Hello www1707"
---> Running in d0817c08cb82
Removing intermediate container d0817c08cb82
---> d93c942a1584
Successfully built d93c942a1584
Successfully tagged test020:latest
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test020 latest d93c942a1584 About a minute ago 1.2MB
busybox latest 3a093384ac30 12 days ago 1.2MB
root@docker-lab:~/020# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2Unable to find image 'registry:2' locally # 运行本地Registry容器
2: Pulling from library/registry
cd784148e348: Pull complete
0ecb9b11388e: Pull complete
918b3ddb9613: Pull complete
5aa847785533: Pull complete
adee6f546269: Pull complete
Digest: sha256:1cd9409a311350c3072fe510b52046f104416376c126a479cef9a4dfe692cf57
Status: Downloaded newer image for registry:2
f9e7d22e21d6e0c03b146a3e2100c135c14203308c4323b0673c45eaea97030d
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test020 latest d93c942a1584 About a minute ago 1.2MB
registry 2 33fbbf4a24e5 9 days ago 24.2MB
busybox latest 3a093384ac30 12 days ago 1.2MB
root@docker-lab:~/020# docker tag test020:latest 127.0.0.1:5000/www1707/test020:v1 # 为上传镜像打tag
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/www1707/test020 v1 d93c942a1584 3 minutes ago 1.2MB
test020 latest d93c942a1584 3 minutes ago 1.2MB
registry 2 33fbbf4a24e5 9 days ago 24.2MB
busybox latest 3a093384ac30 12 days ago 1.2MB
root@docker-lab:~/020# docker push 127.0.0.1:5000/www1707/test020:v1 # 上传镜像
The push refers to repository [127.0.0.1:5000/www1707/test020]
683f499823be: Pushed
v1: digest: sha256:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af size: 527
root@docker-lab:~/020# docker rmi 127.0.0.1:5000/www1707/test020:v1 # 删掉本地镜像
Untagged: 127.0.0.1:5000/www1707/test020:v1
Untagged: 127.0.0.1:5000/www1707/test020@sha256:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af
root@docker-lab:~/020# docker rmi test020:latest
Untagged: test020:latest
Deleted: sha256:d93c942a158487248506ac545d33f6fc27c7af29960a5b139e2ef4510b39f37b
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry 2 33fbbf4a24e5 9 days ago 24.2MB
busybox latest 3a093384ac30 12 days ago 1.2MB
root@docker-lab:~/020# docker pull 127.0.0.1:5000/www1707/test020:v1 # 下载镜像测试
v1: Pulling from www1707/test020
57c14dd66db0: Already exists
Digest: sha256:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af
Status: Downloaded newer image for 127.0.0.1:5000/www1707/test020:v1
root@docker-lab:~/020# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/www1707/test020 v1 d93c942a1584 4 minutes ago 1.2MB
registry 2 33fbbf4a24e5 9 days ago 24.2MB
busybox latest 3a093384ac30 12 days ago 1.2MB