我有一个标记为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登录——username用户名 如果你省略了——password,提示输入密码,这是推荐的,因为它不会存储在你的命令历史中 Docker标签my-image用户名/my-repo Docker推送用户名/my-repo

在dockerhub上创建存储库:

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

$docker push UsernameOnDockerhub/repoNameOnDockerhub:最新

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

"latest":只是标签

dockerhub中还有一个“默认隐私”设置。访问https://hub.docker.com/settings/default-privacy或点击帐户设置->默认隐私。

将切换设置为“private”。

这不是一个完整的解决方案,但至少默认的私有比默认的公共要好。你可以返回并公开你想要的。

以下是将Docker Image推送到DockerHub的私有存储库的步骤

1-首先使用命令检查Docker图像

码头工人的图片

2-查看Docker Tag命令帮助

Docker标签——救命

3-现在标记一个名称,以您创建的图像

DockerHubUser\Private-repoName:tagName(标签名可选。默认名称为最新)

4-在推送镜像到DockerHub Private Repo之前,请先使用命令登录DockerHub

docker login[提供dockerHub用户名和密码登录]

5-现在推Docker映像到您的私人回购使用命令

docker push [options] ImgName[:tag]例如docker push DockerHubUser\Private-repoName:tagName

6-现在导航到DockerHub Private Repo,你会看到Docker映像被推送到你的私有存储库上,在前面的步骤中名称写为TagName

有两种选择:

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.