我有一个标记为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命令参考

其他回答

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

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