2

I have a Spring Boot maven app, which I need to dockerize using jib plugin, and send to azure container registry The registry is set up and ready, including the username, password, etc... My pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <jib-maven-plugin.version>1.7.0</jib-maven-plugin.version>
        <docker.image.prefix>containerregistry0001968.azurecr.io</docker.image.prefix>
        <java.version>1.8</java.version>
        <username>containerregistry0001968</username>
        <password>/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD</password>
        <project.artifactId>demo-springboot-docker-0001968</project.artifactId>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-servicebus-jms-spring-boot-starter</artifactId>
            <version>2.1.7</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>jib-maven-plugin</artifactId>
                <groupId>com.google.cloud.tools</groupId>
                <version>1.8.0</version>
                <configuration>
                    <from>
                        <image>suranagivinod/openjdk8:latest</image>
                    </from>
                    <to>
                        <image>demo-springboot-docker-0001968</image>
                        <auth>
                            <username>containerregistry0001968</username>
                            <password>/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD</password>
                        </auth>
                    </to>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

When I run command " mvn compile jib:build", I get this output:

[INFO] Containerizing application to demo-springboot-docker-0001968...
[WARNING] Base image 'suranagivinod/openjdk8' does not use a specific image digest - build may not be reproducible
[INFO] The base image requires auth. Trying again for suranagivinod/openjdk8...
[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry-1.docker.io
[WARNING] 
Got output:

credentials not found in native keychain

[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry.hub.docker.com
[WARNING] 
Got output:

credentials not found in native keychain

[INFO] Executing tasks:
[INFO] [==========                    ] 31.7% complete
[INFO] > pulling base image manifest
[INFO] > building dependencies layer
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.770 s
[INFO] Finished at: 2020-01-23T16:12:25-06:00
[INFO] Final Memory: 38M/410M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:1.8.0:build (default-cli) on project demo: Build image failed, perhaps you should make sure your credentials for 'registry-1.docker.io/library/demo-springboot-docker-0001968' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for registry-1.docker.io/library/demo-springboot-docker-0001968: 401 Unauthorized
[ERROR] {"details":"incorrect username or password"}
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

The base image is in the public docker hub repo. When I run docker pull ... - I'm able to pull it with no issues.

How can I adjust this pom file, to enable the base image to be pulled?

Eugene Goldberg
  • 14,286
  • 20
  • 94
  • 167
  • 1
    It may be the target image that needs authentication, not the base image: `registry-1.docker.io/library/demo-springboot-docker-0001968: 401 Unauthorized`. I actually think your username and password in your pom.xml are incorrect. And I'd avoid placing them in `pom.xml`. – Chanseok Oh Jan 23 '20 at 23:21

4 Answers4

3

Note the error is for the target image, not the base image.

> make sure your credentials for 'registry-1.docker.io/library/demo-springboot-docker-0001968' are set up correctly.

Also note that the target image refers to the Docker Hub repository (registry-1.docker.io).

If I try your username and password (for Docker Hub),

$ docker login -u containerregistry0001968 -p '/rG=4I26Eogai7a0/OWMKxo2x7OnHIHD'
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password

I get the exact same error message shown in the Jib build log:

incorrect username or password

Your username and password are incorrect. And I would change your password right now, since they are now publicly shown. Or just delete this question.

Chanseok Oh
  • 3,920
  • 4
  • 23
  • 63
1

You think that:

The base image is in the public docker hub repo

Docker says:

$ docker pull uranagivinod/openjdk8:latest
Error response from daemon: pull access denied for uranagivinod/openjdk8, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Try again by first performing docker logout and you will discover by yourself it is actually a private image.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • I did the logout, changed the "from" image to official OpenJDK, was able to do docker pull, but still same issues when using jib – Eugene Goldberg Jan 23 '20 at 23:19
1

The error line points to repository - registry-1.docker.io. I had the same issue, got resolved by prefixing the dockerhub site name - registry.hub.docker.com ie. Please refer to below snippet from my project. Run seperate task ie. mvn compile jib:build Snippet from my pom.xml.(hkmehandiratta is my account id at docker ).

<plugin>
              <groupId>com.google.cloud.tools</groupId>
              <artifactId>jib-maven-plugin</artifactId>
              <version>2.7.1</version>
              <configuration>
                <from>
                  <image>openjdk:8-jdk-alpine</image>
                </from>
                <to>
                  <image>registry.hub.docker.com/hkmehandiratta/${project.name}:${project.version}</image>
                </to>
                <container>
                  <ports>
                    <port>8000</port>
                  </ports>
                </container>
              </configuration>
            </plugin>
This is functional and should resolve the issue.
hmehandi
  • 356
  • 4
  • 11
0

I got the same issue when using jib plugin one times.

Just try to logout first by hitting docker logout in the terminal and then add the following option when making a mvn build.

-D jib.to.auth.username="your-dockerhub-username" -Djib.to.auth.password="your-dockerhub-password"