docker HUB是一个公共的image registry, 不注册账号的话, 可以从docker hub下载public image.
docker search, pull操作不需要登录docker hub就可以对public image进行检索和下载.
如果需要将本地的image 推送到docker hub, 那么你需要注册一个docker hub的账号, 登录, 然后执行push即可.
docker hub的免费用户只能保存public image. 也就是说大家都能搜到并下载你的image.
例如 :
登录docker hub
[root@db-172-16-3-221 ~]# docker login
Username: digoal
Password:
Email: xxx@xx.xx
Login Succeeded
登录后, 会把认证信息保存在.dockercfg文件中.
[root@db-172-16-3-221 ~]# cat ~/.dockercfg
{"https://index.docker.io/v1/":{"auth":"xxxxxxxxxxxx","email":"xxx@xx.xx"}}
查看当前正在运行的container, 例如我们这里有一个名为digoal的container.
[root@db-172-16-3-221 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca64905e843a postgres:9 /docker-entrypoint.s 3 hours ago Up 3 hours 5432/tcp digoal
aab6a732ddbc postgres:9 /docker-entrypoint.s 20 hours ago Up 20 hours 5432/tcp happy_leakey
edae35acc741 postgres:9 /docker-entrypoint.s 20 hours ago Up 20 hours 5432/tcp lonely_mcclintock
7c99c4f4a01f postgres:9 /docker-entrypoint.s 20 hours ago Up 20 hours 5432/tcp pensive_hoover
8238bc46c1da postgres:9 /docker-entrypoint.s 20 hours ago Up 20 hours 5432/tcp grave_thompson
我们把这个container打包成一个image, 把这个image放在digoal用户下.
[root@db-172-16-3-221 ~]# docker commit -a "digoal" -m "this is test" -p digoal digoal/postgres:9.3.5
a7ef5455170da413113de47917b3d4662e46d2835d69b28cfbe9aa919ff28804
查看本地的images, 就能看到刚才打包好的image: digoal/postgres:9.3.5
[root@db-172-16-3-221 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
digoal/postgres 9.3.5 a7ef5455170d 7 seconds ago 212.9 MB
postgres 9.4-beta3 68b6ddf9ca08 8 days ago 213.6 MB
postgres 9.4 68b6ddf9ca08 8 days ago 213.6 MB
postgres 9 935836384c52 8 days ago 212.9 MB
postgres latest 935836384c52 8 days ago 212.9 MB
postgres 9.3 935836384c52 8 days ago 212.9 MB
postgres 9.3.5 935836384c52 8 days ago 212.9 MB
postgres 9.2.9 2a9ab0b9fa56 8 days ago 212.7 MB
postgres 9.2 2a9ab0b9fa56 8 days ago 212.7 MB
postgres 9.1 ee60947f6805 8 days ago 212.1 MB
postgres 9.1.14 ee60947f6805 8 days ago 212.1 MB
postgres 9.0.18 f29be88283f6 8 days ago 211.5 MB
postgres 9.0 f29be88283f6 8 days ago 211.5 MB
postgres 8.4 c57c14beb696 8 days ago 211 MB
postgres 8 c57c14beb696 8 days ago 211 MB
postgres 8.4.22 c57c14beb696 8 days ago 211 MB
postgres 9.4-beta2 bf872395e1d4 2 weeks ago 213.6 MB
然后我们可以将这个image推送到docker hub. 同样是保存在我们登录的digoal用户下.
[root@db-172-16-3-221 ~]# docker push digoal/postgres:9.3.5
The push refers to a repository [digoal/postgres] (len: 1)
Sending image list
Pushing repository digoal/postgres (1 tags)
511136ea3c5a: Image already pushed, skipping
638fd9704285: Image already pushed, skipping
61f7f4f722fb: Image already pushed, skipping
759ce1ba8521: Image already pushed, skipping
05084fa93ca4: Image already pushed, skipping
b9c3e6ba73da: Image already pushed, skipping
e428b525362f: Image already pushed, skipping
74b9c5a96fe2: Image already pushed, skipping
a40cbed3d918: Image already pushed, skipping
adac4c321716: Image already pushed, skipping
c7dac22233f3: Image already pushed, skipping
b95ec4ff2ae8: Image already pushed, skipping
6d9ec1cd8a6f: Image already pushed, skipping
0778b2e9be29: Image already pushed, skipping
1a351aafeb1c: Image already pushed, skipping
789b1440f38b: Image already pushed, skipping
e849841ed55f: Image already pushed, skipping
ee9cafa51046: Image already pushed, skipping
15d042248df3: Image already pushed, skipping
935836384c52: Image already pushed, skipping
a7ef5455170d: Image successfully pushed
Pushing tag for rev [a7ef5455170d] on {https://cdn-registry-1.docker.io/v1/repositories/digoal/postgres/tags/9.3.5}
现在执行search可以检索到我们刚才提交的image.
[root@db-172-16-3-221 ~]# docker search digoal
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
digoal/postgres 0
[参考]
1. https://docs.docker.com/userguide/dockerrepos/
时间: 2024-10-28 20:25:28