我有一个标记为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 tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

然后docker push使用相同的标签。

docker push NAME[:TAG]

例子:

docker tag gvenzl/oracle-xe:21-slim quay.io/repository/yourDirectory/oracle_xe:oracle-xe

docker push quay.io/repository/yourDirectory/oracle_xe:oracle-xe

在dockerhub上创建存储库:

$docker tag IMAGE_ID用户名ondockerhub /repoNameOnDockerhub:最新

$docker push UsernameOnDockerhub/repoNameOnDockerhub:最新

注:此处 "repoNameOnDockerhub":您所提到的名称的存储库已经存在 呈现在dockerhub上

"latest":只是标签

简单的工作解决方案:

访问这里https://hub.docker.com/创建一个私有存储库,例如johnsmith/ PRIVATE -repository,这是您在构建映像时将用于映像的name / repository。

首先,docker登录 其次,我使用“docker build -t johnsmith/private-repository:01 .”(其中01是我的版本名)来创建图像,并且我使用“docker images”来确认创建的图像,例如下面这个黄色框中的图像:(对不起,我不能粘贴表格格式,但只能粘贴文本字符串)

johnsmith/private-repository(REPOSITORY) 01(TAG) c5f4a2861d6e(IMAGE ID) 2 days ago(CREATED) 305MB(SIZE)

第三,我使用docker推送johnsmith/private-repository:01(你的私人回购将在这里的例子https://hub.docker.com/r/johnsmith/private-repository/)

完成了!

有两种选择:

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.