我有一个标记为me / my-image的docker图像,我在dockerhub上有一个名为me-private的私人仓库 . 当我推动我/我的形象时,我最终总是打到公共回购 .
将图像专门推送到私人仓库的确切语法是什么?
您需要先使用 registryhost 正确标记图像:
registryhost
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
然后docker使用相同的标签推送 .
docker push NAME[:TAG]
例:
docker tag 518a41981a6a myRegistry.com/myImage docker push myRegistry.com/myImage
只需三个简单的步骤:
docker login --username username --password password
docker tag my-image username/my-repo
docker push username/my-repo
首先转到Docker Hub帐户并进行回购 . 以下是我的Docker Hub帐户的屏幕截图:
从图片中,你可以看到我的回购是“chuangg”
现在进入回购并通过点击图片名称将其设为私有 . 所以对我来说,我点击了“chuangg / gene_commited_image”,然后我去了设置 - >私有 . 然后我按照屏幕上的说明
如何将你的DOCKER图像上传到DOCKER HUB
Method #1= Pushing your image through the command line (cli)
1) docker commit <container ID> <repo name>/<Name you want to give the image>
docker commit <container ID> <repo name>/<Name you want to give the image>
是的,我认为它必须是容器ID . 它可能不是图像ID .
例如= docker commit 99e078826312 chuangg/gene_commited_image
docker commit 99e078826312 chuangg/gene_commited_image
2) docker run -it chaung/gene_commited_image
docker run -it chaung/gene_commited_image
3) docker login --username=<user username> --password=<user password>
docker login --username=<user username> --password=<user password>
例如= docker login --username=chuangg --email=gc.genechaung@gmail.com
docker login --username=chuangg --email=gc.genechaung@gmail.com
是的,你必须先登录 . 使用“docker logout”注销
4) docker push chuangg/gene_commited_image
docker push chuangg/gene_commited_image
Method #2= Pushing your image using pom.xml and command line.
注意,我使用了名为“build-docker”的Maven配置文件 . 如果您不想使用配置文件,只需删除 <profiles>, <profile>, and <id>build-docker</id> 元素即可 .
<profiles>, <profile>, and <id>build-docker</id>
在父pom.xml中:
<profiles> <profile> <id>build-docker</id> <build> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.18.1</version> <configuration> <images> <image> <name>chuangg/gene_project</name> <alias>${docker.container.name}</alias> <!-- Configure build settings --> <build> <dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir> <assembly> <inline> <fileSets> <fileSet> <directory>${project.basedir}\target</directory> <outputDirectory>.</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </inline> </assembly> </build> </image> </images> </configuration> <executions> <execution> <id>docker:build</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
用于部署Docker镜像的Docker Terminal命令(来自pom.xml所在的目录)= mvn clean deploy -Pbuild-docker docker:push
mvn clean deploy -Pbuild-docker docker:push
注意,方法#2和#3之间的区别在于方法#3有一个额外的 <execution> 用于部署 .
<execution>
Method #3= Using Maven to automatically deploy to Docker Hub
将这些东西添加到您的父pom.xml:
<distributionManagement> <repository> <id>gene</id> <name>chuangg</name> <uniqueVersion>false</uniqueVersion> <layout>legacy</layout> <url>https://index.docker.io/v1/</url> </repository> </distributionManagement> <profiles> <profile> <id>build-docker</id> <build> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.18.1</version> <configuration> <images> <image> <name>chuangg/gene_project1</name> <alias>${docker.container.name}</alias> <!-- Configure build settings --> <build> <dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir> <assembly> <inline> <fileSets> <fileSet> <directory>${project.basedir}\target</directory> <outputDirectory>.</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </inline> </assembly> </build> </image> </images> </configuration> <executions> <execution> <id>docker:build</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>docker:push</id> <phase>install</phase> <goals> <goal>push</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> </project>
转到C:\ Users \ Gene.docker \目录并将其添加到config.json文件中:
现在在您的Docker快速入门终端类型= mvn clean install -Pbuild-docker
mvn clean install -Pbuild-docker
对于那些没有使用Maven配置文件的人,只需输入 mvn clean install
mvn clean install
以下是成功消息的屏幕截图:
这是我的完整pom.xml和我的目录结构的屏幕截图:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.gene.app</groupId> <artifactId>VendingMachineDockerMavenPlugin</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Maven Quick Start Archetype</name> <url>www.gene.com</url> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.gene.sample.Customer_View</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies> <distributionManagement> <repository> <id>gene</id> <name>chuangg</name> <uniqueVersion>false</uniqueVersion> <layout>legacy</layout> <url>https://index.docker.io/v1/</url> </repository> </distributionManagement> <profiles> <profile> <id>build-docker</id> <properties> <java.docker.version>1.8.0</java.docker.version> </properties> <build> <plugins> <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.18.1</version> <configuration> <images> <image> <name>chuangg/gene_project1</name> <alias>${docker.container.name}</alias> <!-- Configure build settings --> <build> <dockerFileDir>${project.basedir}\src\docker\vending_machine_emulator</dockerFileDir> <assembly> <inline> <fileSets> <fileSet> <directory>${project.basedir}\target</directory> <outputDirectory>.</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> </inline> </assembly> </build> </image> </images> </configuration> <executions> <execution> <id>docker:build</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>docker:push</id> <phase>install</phase> <goals> <goal>push</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
这是我的Eclipse目录:
这是我的Dockerfile:
FROM java:8 MAINTAINER Gene Chuang RUN echo Running Dockerfile in src/docker/vending_machine_emulator/Dockerfile directory ADD maven/VendingMachineDockerMavenPlugin-1.0-SNAPSHOT.jar /bullshitDirectory/gene-app-1.0-SNAPSHOT.jar CMD ["java", "-classpath", "/bullshitDirectory/gene-app-1.0-SNAPSHOT.jar", "com/gene/sample/Customer_View" ]
常见错误#1:
错误#1的解决方案=不要将 <execution> 与maven部署阶段同步,因为然后maven尝试部署映像2x并在jar上放置时间戳 . 这就是我使用 <phase>install</phase> 的原因 .
<phase>install</phase>
如果您的docker注册表是私有 and self hosted ,您应该执行以下操作:
docker login <REGISTRY_HOST>:<REGISTRY_PORT> docker tag <IMAGE_ID> <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION> docker push <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
示例:
docker login repo.company.com:3456 docker tag 19fcc4aa71ba repo.company.com:3456/myapp:0.1 docker push repo.company.com:3456/myapp:0.1
有两种选择:
进入集线器,首先创建存储库,并将其标记为私有 . 然后当你推到那个回购时,它将是私有的 . 这是最常用的方法 .
登录您的码头集线器帐户,然后转到您的global settings . 有一个设置允许您设置您推送的存储库的默认可见性 . 默认情况下,它设置为public,但如果将其更改为private,则默认情况下,您推送的所有存储库都将标记为private . 请务必注意,您需要在帐户中提供足够的私人回购,否则在您升级计划之前,回购将会被锁定 .
> docker login [OPTIONS] [SERVER] [OPTIONS]: -u username -p password
例如:
> docker login localhost:8080
> docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
> docker tag myApp:v1 localhost:8080/myname/myApp:v1
>docker push [OPTIONS] NAME[:TAG]
> docker push localhost:8080/myname/myApp:v1
简单工作方案:
到这里 https://hub.docker.com/ 创建一个名称为 johnsmith/private-repository 的PRIVATE存储库,这是构建图像时用于图像的 NAME/REPOSITORY .
https://hub.docker.com/
johnsmith/private-repository
NAME/REPOSITORY
首先, docker login
docker login
其次,我使用“ docker build -t johnsmith/private-repository:01 . " (where 01 is my version name) to create image, and I use " docker images ”来确认创建的图像,如下面的黄色框中所示:(抱歉,我不能粘贴表格格式而只是文本字符串)
docker build -t johnsmith/private-repository:01 .
docker images
johnsmith / private-repository(REPOSITORY)01(TAG)c5f4a2861d6e(IMAGE ID)2天前(已创建)305MB(SIZE)
docker push johnsmith/private-repository:01
完成!
参考: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
ubuntu:16.04
$ docker pull ubuntu:16.04
localhost:5000/my-ubuntu
$ docker tag ubuntu:16.04 localhost:5000/my-ubuntu
localhost:5000
$ docker push localhost:5000/my-ubuntu
$ docker image remove ubuntu:16.04 $ docker image remove localhost:5000/my-ubuntu
$ docker pull localhost:5000/my-ubuntu
部署纯HTTP注册表根据docs.docker.com,这是 very 不安全,是 not recommended .
daemon.json
/etc/docker/daemon.json
C:\ProgramData\docker\config\daemon.json
Docker for Mac
Docker for Windows
Docker icon -> Preferences -> Daemon
insecure registry
如果 daemon.json 文件不存在,请创建它 . 假设文件中没有其他设置,则应具有以下内容:
{ "insecure-registries" : ["myregistrydomain.com:5000"] }
启用了不安全的注册表后,Docker将执行以下步骤:
首先,尝试使用HTTPS .
如果HTTPS可用但证书无效,请忽略有关证书的错误 .
如果HTTPS不可用,请回退到HTTP .
重新启动Docker以使更改生效 .
在dockerhub上创建存储库:
$docker tag IMAGE_ID UsernameOnDockerhub/repoNameOnDockerhub:latest
$docker push UsernameOnDockerhub/repoNameOnDockerhub:latest
Note :这里"repoNameOnDockerhub":您提及的名称的存储库必须出现在dockerhub上
“最新”:只是标签
9 回答
您需要先使用
registryhost
正确标记图像:然后docker使用相同的标签推送 .
例:
只需三个简单的步骤:
docker login --username username --password password
docker tag my-image username/my-repo
docker push username/my-repo
首先转到Docker Hub帐户并进行回购 . 以下是我的Docker Hub帐户的屏幕截图:
从图片中,你可以看到我的回购是“chuangg”
现在进入回购并通过点击图片名称将其设为私有 . 所以对我来说,我点击了“chuangg / gene_commited_image”,然后我去了设置 - >私有 . 然后我按照屏幕上的说明
如何将你的DOCKER图像上传到DOCKER HUB
Method #1= Pushing your image through the command line (cli)
1)
docker commit <container ID> <repo name>/<Name you want to give the image>
是的,我认为它必须是容器ID . 它可能不是图像ID .
例如=
docker commit 99e078826312 chuangg/gene_commited_image
2)
docker run -it chaung/gene_commited_image
3)
docker login --username=<user username> --password=<user password>
例如=
docker login --username=chuangg --email=gc.genechaung@gmail.com
是的,你必须先登录 . 使用“docker logout”注销
4)
docker push chuangg/gene_commited_image
Method #2= Pushing your image using pom.xml and command line.
注意,我使用了名为“build-docker”的Maven配置文件 . 如果您不想使用配置文件,只需删除
<profiles>, <profile>, and <id>build-docker</id>
元素即可 .在父pom.xml中:
用于部署Docker镜像的Docker Terminal命令(来自pom.xml所在的目录)=
mvn clean deploy -Pbuild-docker docker:push
注意,方法#2和#3之间的区别在于方法#3有一个额外的
<execution>
用于部署 .Method #3= Using Maven to automatically deploy to Docker Hub
将这些东西添加到您的父pom.xml:
转到C:\ Users \ Gene.docker \目录并将其添加到config.json文件中:
现在在您的Docker快速入门终端类型=
mvn clean install -Pbuild-docker
对于那些没有使用Maven配置文件的人,只需输入
mvn clean install
以下是成功消息的屏幕截图:
这是我的完整pom.xml和我的目录结构的屏幕截图:
这是我的Eclipse目录:
这是我的Dockerfile:
常见错误#1:
错误#1的解决方案=不要将
<execution>
与maven部署阶段同步,因为然后maven尝试部署映像2x并在jar上放置时间戳 . 这就是我使用<phase>install</phase>
的原因 .如果您的docker注册表是私有 and self hosted ,您应该执行以下操作:
示例:
有两种选择:
进入集线器,首先创建存储库,并将其标记为私有 . 然后当你推到那个回购时,它将是私有的 . 这是最常用的方法 .
登录您的码头集线器帐户,然后转到您的global settings . 有一个设置允许您设置您推送的存储库的默认可见性 . 默认情况下,它设置为public,但如果将其更改为private,则默认情况下,您推送的所有存储库都将标记为private . 请务必注意,您需要在帐户中提供足够的私人回购,否则在您升级计划之前,回购将会被锁定 .
首先登录您的私人存储库 .
例如:
然后为您的私有存储库标记您的图像
例如:
最后将您的托管图像推送到您的私有存储库
例如:
参考
简单工作方案:
到这里
https://hub.docker.com/
创建一个名称为johnsmith/private-repository
的PRIVATE存储库,这是构建图像时用于图像的NAME/REPOSITORY
.首先,
docker login
其次,我使用“
docker build -t johnsmith/private-repository:01 .
" (where 01 is my version name) to create image, and I use "docker images
”来确认创建的图像,如下面的黄色框中所示:(抱歉,我不能粘贴表格格式而只是文本字符串)docker push johnsmith/private-repository:01
(您的私人仓库将在这里示例https://hub.docker.com/r/johnsmith/private-repository/)完成!
参考:dock.docker.com
本主题提供有关部署和配置注册表的基本信息
运行本地注册表
在部署注册表之前,需要在主机上安装Docker .
使用如下命令启动注册表容器:
start_registry.sh
将图像从Docker Hub复制到您的注册处
ubuntu:16.04
图像 .localhost:5000/my-ubuntu
. 这会为现有图像创建一个附加标记 . 当标记的第一部分是主机名和端口时,Docker在推送时将其解释为注册表的位置 .localhost:5000
的本地注册表:localhost:5000/my-ubuntu
图像 .localhost:5000/my-ubuntu
图像 .部署纯HTTP注册表
根据docs.docker.com,这是 very 不安全,是 not recommended .
daemon.json
文件,其默认位置在Linux上为/etc/docker/daemon.json
或在Windows Server上为C:\ProgramData\docker\config\daemon.json
. 如果使用Docker for Mac
或Docker for Windows
,请单击Docker icon -> Preferences -> Daemon
,添加insecure registry
.如果
daemon.json
文件不存在,请创建它 . 假设文件中没有其他设置,则应具有以下内容:启用了不安全的注册表后,Docker将执行以下步骤:
首先,尝试使用HTTPS .
如果HTTPS可用但证书无效,请忽略有关证书的错误 .
如果HTTPS不可用,请回退到HTTP .
重新启动Docker以使更改生效 .
在dockerhub上创建存储库:
$docker tag IMAGE_ID UsernameOnDockerhub/repoNameOnDockerhub:latest
$docker push UsernameOnDockerhub/repoNameOnDockerhub:latest
Note :这里"repoNameOnDockerhub":您提及的名称的存储库必须出现在dockerhub上
“最新”:只是标签