我有一个标记为me/my-image的docker映像,我在dockerhub上有一个命名为me-private的私有repo。 当我推行我自己/我的形象时,我最终总是撞上公共回购。
具体将映像推到私有repo的确切语法是什么?
我有一个标记为me/my-image的docker映像,我在dockerhub上有一个命名为me-private的私有repo。 当我推行我自己/我的形象时,我最终总是撞上公共回购。
具体将映像推到私有repo的确切语法是什么?
当前回答
如果有人正在寻找一种快速将所有图像推送到私有存储库的方法, 你可以使用我的bash脚本-它会将所有Docker映像推送到新的私有注册表:
#!/bin/bash
repo="<change_to_your_new_repo>"
remote_repo="<the_new_repo_name>"
for img in $(docker images --format "{{.Repository}}:{{.Tag}}")
do
image=$(echo $img | cut -d ":" -f 1)
image_tag=$(echo $img | cut -d ":" -f 2)
docker image tag $image:$image_tag $repo/$remote_repo/$image:$image_tag
docker image push $repo/$remote_repo/$image:$image_tag
docker rmi $repo/$remote_repo/$image:$image_tag
done
其他回答
首先,你需要用你的注册主机正确地标记你的图像:
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
然后docker push使用相同的标签。
docker push NAME[:TAG]
例子:
docker tag 518a41981a6a myRegistry.com/myImage
docker push myRegistry.com/myImage
当推送到Docker Hub帐户时,无论是公共帐户还是私有帐户,过程都是相同的。
警察说:
我有一个标记为me/my-image的docker映像,我在dockerhub上有一个命名为me-private的私有repo。 当我推行我自己/我的形象时,我最终总是撞上公共回购。
直接的问题是私有回购(me-private)似乎与映像(my-image)具有不同的名称。repo和映像必须具有相同的名称(减去任何标记)。
TLDR; 一个名为my-image或my-image:标签的图像必须有一个my-image的回收名。
因为行动中心的回购被命名为我私人的, Docker Hub不会将它们视为相同的,并将创建名为my-image的新回购。
(默认情况下,新的回购将是公开的,除非您更改设置使所有存储库都是私有的。)
截至2022年6月,建立Docker Hub回购的流程是:
给定以下值:
用户名= yourusername 图像名称=图像 标签=标签
1)标记(或提交)本地图像,添加一个前缀与您的用户名:
docker tag theimage:thetag yourusername/theimage:thetag
注:
如果你在一个组织中,你需要双前缀的图像-像这样:
docker tag theimage:thetag yourusername/yourorganizationname/theimage:thetag
如果你的标签是最新的,:标签部分可以省略;Docker假设:latest如果你没有输入:thetag部分
2)将前缀图像推送到Docker Hub:
docker push yourusername/theimage:thetag
OR
docker push yourusername/yourorganizationname/theimage:thetag
对于私人回购,这些额外步骤之一是必要的:
要么
在上述第1步之前,在Docker Hub帐户中创建一个私有存储库
请记住,存储库名称必须与您计划推送的映像相同。不要在存储库名称中包含thetag部分。例如,如果你的映像是ubuntu:14.04,你可以将你的存储库命名为ubuntu。(所有带标签的图片,如ubuntu:latest, ubuntu:14.04等,都将进入ubuntu repo。)
Or
如果你没有提前创建存储库(这不是必需的!):转到Docker Hub中的帐户;点击新推出的回购,然后它的设置选项卡-并使你的回购私有。
在dockerhub上创建存储库:
$docker tag IMAGE_ID用户名ondockerhub /repoNameOnDockerhub:最新
$docker push UsernameOnDockerhub/repoNameOnDockerhub:最新
注:此处 "repoNameOnDockerhub":您所提到的名称的存储库已经存在 呈现在dockerhub上
"latest":只是标签
dockerhub中还有一个“默认隐私”设置。访问https://hub.docker.com/settings/default-privacy或点击帐户设置->默认隐私。
将切换设置为“private”。
这不是一个完整的解决方案,但至少默认的私有比默认的公共要好。你可以返回并公开你想要的。
有两种选择:
Go into the hub, and create the repository first, and mark it as private. Then when you push to that repo, it will be private. This is the most common approach. log into your docker hub account, and go to your global settings. There is a setting that allows you to set what your default visability is for the repositories that you push. By default it is set to public, but if you change it to private, all of your repositories that you push will be marked as private by default. It is important to note that you will need to have enough private repos available on your account, or else the repo will be locked until you upgrade your plan.