pushing docker image to dockerhub

后端 未结 3 2045
感情败类
感情败类 2020-12-25 14:30

I ve created my own docker file ( that runs a shell script which prints \"helloworld\"). The image is \"hellodocker\" and the tag is \"mytag\" I now have:

ba         


        
相关标签:
3条回答
  • 2020-12-25 15:02

    You either need to tag it as <myuser>/hellodocker when you build it, e g

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

    or create a new tag tied to the same image, i e

    docker tag hellodocker:mytag <myuser>/hellodocker:mytag
    
    0 讨论(0)
  • 2020-12-25 15:02

    First go to your Docker Hub account and make the repo. Here is a screenshot of my Docker Hub account:

    From the pic, you can see my repo is “chuangg”

    HOW TO UPLOAD YOUR DOCKER IMAGE ONTO 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>

    Yes, I think it has to be the container ID. It probably cannot be the image ID.

    For example= 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>

    For example= docker login --username=chuangg --email=gc.genechaung@gmail.com

    Yes, you have to login first. Logout using “docker logout”

    4) docker push chuangg/gene_commited_image

    Method #2= Pushing your image using pom.xml and command line.

    Note, I used a Maven Profile called “build-docker”. If you don’t want to use a profile, just remove the <profiles>, <profile>, and <id>build-docker</id> elements.

    Inside the parent 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 Command to deploy the Docker Image (from the directory where your pom.xml is located)= mvn clean deploy -Pbuild-docker docker:push

    For those of you not using a Maven Profile, the command would simply be mvn clean deploy docker:push

    Note, the difference between Method #2 and #3 is that Method #3 has an extra <execution> for the deployment.

    Method #3= Using Maven to automatically deploy to Docker Hub

    Add this stuff to your parent 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>
    

    Go to C:\Users\Gene.docker\ directory and add this to your config.json file:

    Now in your Docker Quickstart Terminal type= mvn clean install -Pbuild-docker

    For those of you not using a Profile, just type mvn clean install

    Here is a screenshot of what it will look like if it works:

    Here is my full pom.xml and a screenshot of my directory structure:

    <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>
    

    Here is my Eclipse Directory:

    Here is my 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" ] 
    

    Common Error #1:

    Solution for Error #1= Do not sync the <execution> with maven deploy phase because then maven tries to deploy the image 2x and puts a timestamp on the jar. That’s why I used <phase>install</phase>.

    0 讨论(0)
  • 2020-12-25 15:08

    If you want hellodocker repository under myuserid namespace, you have to first tag your local hellodocker to myuseridlike:

    docker tag hellodocker myuserid/hellodocker

    And then push this myuserid/hellodocker repository to hub like:

    docker push myuserid/hellodocker

    0 讨论(0)
提交回复
热议问题