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

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


当前回答

首先转到Docker Hub帐户并进行回购。这是我Docker Hub账户的截图:

从图片中,你可以看到我的回购是“chuangg”

现在进入repo,通过单击图像的名称将其设置为私有。对我来说,我点击了“chuangg/gene_commited_image”,然后我进入设置->设置为私有。然后我按照屏幕上的说明进行操作

如何上传你的docker图像到docker hub

方法#1=通过命令行(cli)推送图像

1) docker commit <容器ID> <repo name>/<你想给映像的名称>

是的,我想应该是集装箱ID。它可能不是映像ID。

例如= docker commit 99e078826312 chuangg/gene_commited_image

2) docker运行- chung /gene_commited_image

3) docker login——username=<用户名>——password=<用户密码>

例如= docker login——username=chuangg——email=gc.genechaung@gmail.com

是的,你必须先登录。使用" docker Logout "退出

4) docker push chuangg/gene_commited_image

方法#2=使用pom.xml和命令行推送图像。

注意,我使用了一个名为“build-docker”的Maven概要文件。如果您不想使用概要文件,只需删除<profiles>、<profile>和<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 Terminal部署Docker镜像的命令(从pom.xml所在目录)= mvn clean deploy -Pbuild-docker Docker:push

注意,方法#2和方法#3之间的区别是方法#3有一个额外的<execution>用于部署。

方法#3=使用Maven自动部署到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。并将其添加到您的配置中。json文件:

现在在Docker快速入门终端类型= mvn clean install -Pbuild-docker

对于那些不使用Maven Profiles的人,只需输入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>。

其他回答

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

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

有两种选择:

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.

当推送到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中的帐户;点击新推出的回购,然后它的设置选项卡-并使你的回购私有。

如果有人正在寻找一种快速将所有图像推送到私有存储库的方法, 你可以使用我的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 Hub帐户并进行回购。这是我Docker Hub账户的截图:

从图片中,你可以看到我的回购是“chuangg”

现在进入repo,通过单击图像的名称将其设置为私有。对我来说,我点击了“chuangg/gene_commited_image”,然后我进入设置->设置为私有。然后我按照屏幕上的说明进行操作

如何上传你的docker图像到docker hub

方法#1=通过命令行(cli)推送图像

1) docker commit <容器ID> <repo name>/<你想给映像的名称>

是的,我想应该是集装箱ID。它可能不是映像ID。

例如= docker commit 99e078826312 chuangg/gene_commited_image

2) docker运行- chung /gene_commited_image

3) docker login——username=<用户名>——password=<用户密码>

例如= docker login——username=chuangg——email=gc.genechaung@gmail.com

是的,你必须先登录。使用" docker Logout "退出

4) docker push chuangg/gene_commited_image

方法#2=使用pom.xml和命令行推送图像。

注意,我使用了一个名为“build-docker”的Maven概要文件。如果您不想使用概要文件,只需删除<profiles>、<profile>和<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 Terminal部署Docker镜像的命令(从pom.xml所在目录)= mvn clean deploy -Pbuild-docker Docker:push

注意,方法#2和方法#3之间的区别是方法#3有一个额外的<execution>用于部署。

方法#3=使用Maven自动部署到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。并将其添加到您的配置中。json文件:

现在在Docker快速入门终端类型= mvn clean install -Pbuild-docker

对于那些不使用Maven Profiles的人,只需输入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>。