我有一个标记为me/my-image的docker映像,我在dockerhub上有一个命名为me-private的私有repo。 当我推行我自己/我的形象时,我最终总是撞上公共回购。

具体将映像推到私有repo的确切语法是什么?


当前回答

首先登录您的私有存储库。

> docker login [OPTIONS] [SERVER]

[OPTIONS]: 
-u username 
-p password

eg:

> docker login localhost:8080

然后为您的私有存储库标记您的映像

> docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

eg:

> docker tag myApp:v1 localhost:8080/myname/myApp:v1

最后将您的标记图像推到您的私有存储库

>docker push [OPTIONS] NAME[:TAG]

eg:

> docker push localhost:8080/myname/myApp:v1

参考

Docker命令参考

其他回答

裁判:dock.docker.com

介绍部署和配置注册表的基本信息

运行本地注册表

在部署注册表之前,需要在主机上安装Docker。

使用如下命令启动注册表容器:

start_registry.sh

#!/bin/bash

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /data/registry:/var/lib/registry \
  registry:2

从Docker Hub复制一个映像到注册表

Pull the ubuntu:16.04 image from Docker Hub. $ docker pull ubuntu:16.04 Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing. $ docker tag ubuntu:16.04 localhost:5000/my-ubuntu Push the image to the local registry running at localhost:5000: $ docker push localhost:5000/my-ubuntu Remove the locally-cached images. This does not remove the localhost:5000/my-ubuntu image from your registry. $ docker image remove ubuntu:16.04 $ docker image remove localhost:5000/my-ubuntu Pull the localhost:5000/my-ubuntu image from your local registry. $ docker pull localhost:5000/my-ubuntu

Deploy a plain HTTP registry

根据docs.docker.com,这是非常不安全的,不建议。

Edit the daemon.json file, whose default location is /etc/docker/daemon.json on Linux or C:\ProgramData\docker\config\daemon.json on Windows Server. If you use Docker for Mac or Docker for Windows, click Docker icon -> Preferences -> Daemon, add in the insecure registry. If the daemon.json file does not exist, create it. Assuming there are no other settings in the file, it should have the following contents: { "insecure-registries" : ["myregistrydomain.com:5000"] } With insecure registries enabled, Docker goes through the following steps: First, try using HTTPS. If HTTPS is available but the certificate is invalid, ignore the error about the certificate. If HTTPS is not available, fall back to HTTP. Restart Docker for the changes to take effect.

首先,你需要用你的注册主机正确地标记你的图像:

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

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

将切换设置为“private”。

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

简单的工作解决方案:

访问这里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/)

完成了!

在dockerhub上创建存储库:

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

$docker push UsernameOnDockerhub/repoNameOnDockerhub:最新

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

"latest":只是标签