How to push Docker image to private repository

Keywords: Docker Maven xml Apache

This article is translated from: How to push a docker image to a private repository

I have a docker images tagged as me / my image, and I have a private repo on the dockerhub named me private. When I push my me / my image, I end up always hiding the public repo.

What is the exact syntax to specifically push my image to my private repo?

#1st floor

reference resources: https://stackoom.com/question/1uwyG/ How to push Docker image to private repository

#2nd floor

You need to tag your image correctly first with your registryhost:

docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]

Then docker push using that same tag.

docker push NAME[:TAG]

Example:

docker tag 518a41981a6a myRegistry.com/myImage
docker push myRegistry.com/myImage

#3rd floor

There are two options:

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

  2. log into your docker hub account, and go to your global settings . log in to your Docker Hub account and go to your Global settings . There is a setting that allows you to set what your default visibility 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.

#4th floor

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"

Now go into the repo and make it private by clicking on your image's name. So for me, I clicked on “chuangg/gene_commited_image, then I went to settings - > make private_ commited_ Image, then go to settings - > set private. Then I followed the on screen instructions

HOW TO UPLOAD YOUR DOCKER IMAGE ONTO DOCKER HUB

Method 1 = push your image through the command line (cli) method 1 = push image through the command line (cli)

1) docker commit <container ID> <repo name>/<Name you want to give the image> 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 for example = docker commit 99e078826312 chuangg/gene_commited_image

2) docker run -it chaung/gene_commited_image 2) docker run -it chaung/gene_commited_image

3) docker login --username=<user username> --password=<user password> 3) docker login --username=<user username> --password=<user password>

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

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

4) docker push chuangg/gene_commited_image 4) docker push chuangg/gene_commited_image

Method #2= Pushing your image using pom.xml Method 2 = use pom.xml And command line push images.

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 : at parent pom.xml Medium:

<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 Docker Terminal command to deploy docker image (from pom.xml Directory = MVN clean deploy - pbuild docker docker:push

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

Method 3 = using Maven to automatically deploy to Docker Hub method 3 = using Maven to automatically deploy to Docker Hub

Add this stuff to your parent pom.xml : add this to your father pom.xml Medium:

    <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: go to C: \ \ users\ Gene.docker \Directory and add it to your config.json In the file:

Now in your Docker Quickstart Terminal type = MVN clean install - pbuild docker now enter type = MVN clean install - pbuild docker in your Docker Quickstart Terminal

For those of you not using Maven Profiles, just type mvn clean install

Here is the screenshot of the success message:

Here is my full pom.xml And a screenshot of my directory structure pom.xml 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: 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 >.

#5th floor

Just three simple steps:

  1. docker login --username username

    • Prompts for password if you recommend -- password which is recommended as it doesn't store it in your command history
  2. docker tag my-image username/my-repo

  3. docker push username/my-repo

#6th floor

If you docker registry is private and self hosted you should do the following: if your Docker registry is private and self managed, you should do the following:

docker login <REGISTRY_HOST>:<REGISTRY_PORT>
docker tag <IMAGE_ID> <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>
docker push <REGISTRY_HOST>:<REGISTRY_PORT>/<APPNAME>:<APPVERSION>

Example:

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

Posted by wenxi on Thu, 04 Jun 2020 22:52:02 -0700