把docker图片推到dockerhub

我创build了自己的docker文件(运行一个shell脚本,打印“helloworld”)。 图像是“hellodocker”,标签是“mytag”我现在有:

bash-3.2$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE hellodocker mytag 3514c8dc11a8 39 minutes ago 2.433 MB busybox buildroot-2013.08.1 d200959a3e91 10 weeks ago 2.489 MB busybox ubuntu-14.04 37fca75d01ff 10 weeks ago 5.609 MB busybox ubuntu-12.04 fd5373b3d938 10 weeks ago 5.455 MB busybox buildroot-2014.02 a9eb17255234 10 weeks ago 2.433 MB busybox latest a9eb17255234 10 weeks ago 2.433 MB docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 97c29510069e hellodocker:mytag /bin/sh -c /Users/in 33 minutes ago Exited (127) 26 minutes ago happy_pasteur 8d04a1385c24 hellodocker:mytag /bin/sh -c /Users/in 37 minutes ago Exited (127) 30 minutes ago mad_bell 8998d61c0513 hellodocker:mytag /bin/sh -c /Users/in 37 minutes ago Exited (127) 30 minutes ago boring_thompson 64314c304a29 hellodocker:mytag /bin/sh -c /Users/in 37 minutes ago Exited (127) 31 minutes ago sad_wilson 8bc20e0555b8 hellodocker:mytag /bin/sh -c /Users/in 38 minutes ago Exited (127) 31 minutes ago sleepy_mayer 97664a4ba870 hellodocker:mytag . 38 minutes ago kickass_poincare 8bb752631cb6 busybox:buildroot-2014.02 /bin/echo Hello Doct 18 hours ago Exited (0) 18 hours ago dreamy_kowalevski 6aa66b55ca94 busybox:buildroot-2014.02 bash-3.2$ sudo docke 18 hours ago ecstatic_lovelace 2cc657f65342 busybox:buildroot-2014.02 /bin/echo Hello Dock 18 hours ago Exited (0) 18 hours ago dreamy_poincare 

如何将docker映像推送到dockerhub? 我使用docker push <myuserid>/hellodocker 。 这给了一个'没有这样的id`错误。 我错过了什么? 提前致谢。

当你build立它时,你需要把它标记为<myuser>/hellodocker ,例如

 docker build -t <myuser>/hellodocker:mytag . 

或者创build绑定到相同图像的新标签,即

 docker tag hellodocker:mytag <myuser>/hellodocker:mytag 

如果你想在myuserid命名空间下的hellodocker仓库,你必须首先标记你的本地hellodocker myuserid如:

docker标签hellodocker myuserid / hellodocker

然后推这个myuserid/hellodocker存储库像集线器一样:

docker推myuserid / hellodocker

首先转到您的Docker Hub帐户并进行回购。 以下是我的Docker Hub帐户的屏幕截图: 在这里输入图像说明

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

如何上传你的DOCKER图像到DOCKER HUB上

方法#1 =通过命令行推送图像(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> --email=<user email address>

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

是的,你必须先login。 使用“docker注销”注销

4) docker push chuangg/gene_commited_image

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

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

对于那些不使用Maven Profile的人来说,这个命令可以简单地用mvn clean deploy 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.docker \目录,并将其添加到您的config.json文件中: 在这里输入图像说明

现在在你的Docker Quickstart Terminal中input= mvn clean install -Pbuild-docker

对于那些不使用configuration文件的用户,只需键入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: 在这里输入图像说明

错误解决scheme#1 =不要将<execution>与maven deploy阶段同步,因为然后maven试图部署图像2x并在jar上放置一个时间戳。 这就是我使用<phase>install</phase>