Jib: Not clear about how to set up credential for docker.io in maven

Created on 11 Jul 2018  路  11Comments  路  Source: GoogleContainerTools/jib

Description of the issue:
Not able to build the docker image because of authentication.

Expected behavior:
(1) credential should be picked up by the plugin and then it's able to build the docker image which will be auto pushed to docker.io
(2) how if I only want to build the docker image locally without auto push
Steps to reproduce:
mvn clean compile jib:build

Environment:
Mac OS
Apache Maven 3.5.4
jib-maven-plugin Configuration:

 <plugins>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>0.9.2</version>
        <configuration>
          <from>
            <image>openjdk:alpine</image>
          </from>
          <to>
            <image>registry.hub.docker.com/{my-username}/image-built-with-jib</image>
          </to>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

maven settings Configuration:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>${user.home}/.m2/my-repository</localRepository>
  <servers>
    <server>
      <id>registry.hub.docker.com</id>
      <username>{username}</username>
      <password>{password}</password>
    </server>
  </servers>
</settings>

Log output:
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:0.9.2:build (default) on project demo: Build image failed, perhaps you should make sure your credentials for 'registry.hub.docker.com' are set up correctly: com.google.api.client.http.HttpResponseException: 401 Unauthorized
[ERROR] {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"library/openjdk","Action":"pull"}]}]}

prioritp0

All 11 comments

This looks like a regression we may have introduced in #414 . The error means that pulling the openjdk image from DockerHub is not working. This is because even though the openjdk image does not require credentials to pull, DockerHub still needs to authenticate via its token service. We will need to put our custom RegistryAuthenticator back to use here.

Correct me if I am wrong, but isn't it that @kuanghaochina can't push an image to registry.hub.docker.com? Also, I believe Jib doesn't pick up the servers info fron Maven settings.xml? I thought you would set <credHelper> in pom.xml, but I could be wrong.

(2) how if I only want to build the docker image locally without auto push

@kuanghaochina if you have docker installed locally, you can run mvn compile jib:dockerBuild to save your image locally.

@chanseokoh Reading the log output in @kuanghaochina 's issue description, it looks like the unauthorized failure is with pulling the openjdk image:

[ERROR] {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"library/openjdk","Action":"pull"}]}]}

Using credentials from Maven settings is supported (https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#using-maven-settings)

Ah, I got it wrong. Thanks!

@chanseokoh Thanks for the info.
@coollog You are right. I do have the tag in my Maven settings. And, I would like to use the docker registry, so what should be put in tag, "registry.hub.docker.com" ?

@kuanghaochina @pig4cloud I am working on a fix for this issue. Will update this when the fix is merged/released in version 0.9.4

FYI, I did meet the 401 authentication error today, with docker-credential-pass, however docker command works well. I changed the version back to 0.9.0. All works well for now.

@coollog You are right. I do have the tag in my Maven settings. And, I would like to use the docker registry, so what should be put in tag, "registry.hub.docker.com" ?

@kuanghaochina yeah, looks like you put registry.hub.docker.com into the <id> element, according to https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#using-maven-settings

@kuanghaochina @pig4cloud @maxatcn We just released version 0.9.4. Try updating to that version and your issue should hopefully be fixed :)

Thanks @coollog . This is to update 0.9.4 fixed '401 unauthorized' issue, all works fine for now.

@coollog It works :) Thanks.

Was this page helpful?
0 / 5 - 0 ratings