欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker镜像管理

程序员文章站 2022-04-19 08:53:13
...

目录

使用DockerHub管理Docker镜像

搭建私有仓库管理Docker镜像


使用DockerHub管理Docker镜像

访问https://hub.docker.com/申请一个自己的账号

Docker镜像管理

注册后选择免费的社区版即可

Docker镜像管理

经过邮箱验证后,即可创建自己的镜像库了

Docker镜像管理

 这里我们选择创建一个私有镜像库

Docker镜像管理

在创建镜像库时,我们可以选择关联GitHub,并设置自定义构建规则:此时每当我们向GitHub中gittesting库的master分支push代码后,都会自动构建docker镜像并将该镜像上传至DockerHub

Docker镜像管理

这样DockerHub上的镜像库就创建好了 

 Docker镜像管理

然后我在GitHub中gittesting库的master分支下新增了一个DockerFile文件,文件内容为

from java

提交后果然触发了DockerHub的自动构建

Docker镜像管理

$ docker login -u seanzou6688 -p ******
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in C:\Users\sean\.docker\config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

$ docker pull seanzou6688/sean_images
Using default tag: latest
latest: Pulling from seanzou6688/sean_images
5040bd298390: Pull complete
fce5728aad85: Pull complete
76610ec20bf5: Pull complete
60170fec2151: Pull complete
e98f73de8f0d: Pull complete
11f7af24ed9c: Pull complete
49e2d6393f32: Pull complete
bb9cdec9c7f3: Pull complete
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for seanzou6688/sean_images:latest
docker.io/seanzou6688/sean_images:latest

$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
seanzou6688/sean_images   latest              d23bdf5b1b1b        3 years ago         643MB

$ docker tag seanzou6688/sean_images seanzou6688/sean_images:1.0

$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
seanzou6688/sean_images   1.0                 d23bdf5b1b1b        3 years ago         643MB
seanzou6688/sean_images   latest              d23bdf5b1b1b        3 years ago         643MB

$ docker push seanzou6688/sean_images:1.0
The push refers to repository [docker.io/seanzou6688/sean_images]
35c20f26d188: Layer already exists
c3fe59dd9556: Layer already exists
6ed1a81ba5b6: Layer already exists
a3483ce177ce: Layer already exists
ce6c8756685b: Layer already exists
30339f20ced0: Layer already exists
0eb22bfb707d: Layer already exists
a2ae92ffcd29: Layer already exists
1.0: digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d size: 2000

再看一下DockerHub就可以发现上传成功了

Docker镜像管理

 

搭建私有仓库管理Docker镜像

$ docker search registry
NAME		DESCRIPTION                                     STARS	OFFICIAL	AUTOMATED
registry	The Docker Registry 2.0 implementation for s…   2899	[OK]   

$ docker pull registry
Using default tag: latest
latest: Pulling from library/registry
486039affc0a: Pull complete
ba51a3b098e6: Pull complete
8bb4c43d6c8e: Pull complete
6f5f453e5f2d: Pull complete
42bc10b72f42: Pull complete
Digest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

$ docker images registry
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
registry                  latest              708bc6af7e5e        2 months ago        25.8MB

$ docker run -d -p 5000:5000 registry
dc25f40dbacee62e69909b7153a6a333173020e815e333780f98c4137461330f

可以发现私有库已经成功启动了,上传一个镜像尝试一下

需要注意的是,默认会push到DockerHub,所以一定要用Docker Tag命令重新打Tag将push地址修改为localhost:5000

$ docker tag seanzou6688/sean_images:1.0 localhost:5000/seanzou6688/sean_images:1.0

$ docker images
REPOSITORY                               TAG                 IMAGE ID            CREATED             SIZE
......
seanzou6688/sean_images                  1.0                 d23bdf5b1b1b        3 years ago         643MB
seanzou6688/sean_images                  latest              d23bdf5b1b1b        3 years ago         643MB
localhost:5000/seanzou6688/sean_images   1.0                 d23bdf5b1b1b        3 years ago
......

$ docker push localhost:5000/seanzou6688/sean_images:1.0
The push refers to repository [localhost:5000/seanzou6688/sean_images]
35c20f26d188: Pushed
c3fe59dd9556: Pushed
6ed1a81ba5b6: Pushed
a3483ce177ce: Pushed
ce6c8756685b: Pushed
30339f20ced0: Pushed
0eb22bfb707d: Pushed
a2ae92ffcd29: Pushed
1.0: digest: sha256:f841a2abd0422364ec94bb633a56707a38c330179f2bbccebd95f9aff4a36808 size: 2000

$ curl -XGET http://192.168.99.100:5000/v2/_catalog
{"repositories":["seanzou6688/sean_images"]}

$ curl -XGET http://192.168.99.100:5000/v2/seanzou6688/sean_images/tags/list
{"name":"seanzou6688/sean_images","tags":["1.0"]}

 

相关标签: Docker