Dockerfile-maven: Can't get push to work

Created on 4 Jan 2018  路  14Comments  路  Source: spotify/dockerfile-maven

Can you be a little more specific about what parameters I need to add my maven pom.xml file or maven settings.xml file to push my image up to hub.docker.com?

I've tried adding the following and its doesnt work...

The settings.xml...

`<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>hub.docker.com</id>
            <username>davout</username>
            <password>xxx</password>
        </server>
    </servers>
</settings>`

The pom.xml file as...

````
davout

`
com.spotify
dockerfile-maven-plugin
1.3.7

davout
xxxx
${docker.image.prefix}/${project.artifactId}
true

target/${project.build.finalName}.jar


```

The log output shows the following errors....

`"D:\Program Files\Java\jdk1.8.0_112\bin\java" -Dmaven.multiModuleProjectDirectory=D:\Ian\Documents\github\eis-config-server "-Dmaven.home=D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5\lib\idea_rt.jar=59446:D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.5plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.2.5 com.spotify:dockerfile-maven-plugin:1.3.7:push
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building eis-config-server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- dockerfile-maven-plugin:1.3.7:push (default-cli) @ eis-config-server ---
[WARNING] Did not find maven server configuration for docker server docker.io
[INFO] The push refers to a repository [docker.io/davout/eis-config-server]
[INFO] Image a2ec6c5df22a: Preparing
[INFO] Image 69cc5717c281: Preparing
[INFO] Image 5b1e27e74327: Preparing
[INFO] Image 04a094fe844e: Preparing
[ERROR] denied: requested access to the resource is denied
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not push image
at com.spotify.plugin.dockerfile.PushMojo.execute(PushMojo.java:90)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute(AbstractDockerMojo.java:246)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute(AbstractDockerMojo.java:235)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: com.spotify.docker.client.exceptions.DockerException: denied: requested access to the resource is denied
at com.spotify.plugin.dockerfile.LoggingProgressHandler.handleError(LoggingProgressHandler.java:105)
at com.spotify.plugin.dockerfile.LoggingProgressHandler.progress(LoggingProgressHandler.java:63)
at com.spotify.docker.client.ProgressStream.tail(ProgressStream.java:74)
at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1291)
at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1271)
at com.spotify.plugin.dockerfile.PushMojo.execute(PushMojo.java:88)
... 25 more
[WARNING] Did not find maven server configuration for docker server docker.io
[INFO] The push refers to a repository [docker.io/davout/eis-config-server]
[INFO] Image a2ec6c5df22a: Preparing
[INFO] Image 69cc5717c281: Preparing
[INFO] Image 5b1e27e74327: Preparing
[INFO] Image 04a094fe844e: Preparing
[ERROR] denied: requested access to the resource is denied
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.654 s
[INFO] Finished at: 2018-01-04T14:44:21+00:00
[INFO] Final Memory: 33M/633M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.7:push (default-cli) on project eis-config-server: Could not push image: denied: requested access to the resource is denied -> [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

Process finished with exit code 1
`

Most helpful comment

I can confirm the above is working. I created a new ~/.m2/settings.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers>
    <server>
      <id>docker.io</id>
      <username>mydockerhub_username</username>
      <password>mydockerhub_password</password>
    </server>
  </servers>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

And then had a pom file as follows:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mydomain</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>demo</name>
  <description>Demo project for Spring Boot</description>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
    <relativePath/>
    <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <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>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <version>1.3.7</version>
        <executions>
          <execution>
            <id>default</id>
            <goals>
              <goal>build</goal>
              <goal>push</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <repository>mydockerhub_username/springboothelloworld</repository>
          <tag>${project.version}</tag>
          <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
          <buildArgs>
            <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
          </buildArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I just thought it would be good to give complete files as examples.

All 14 comments

I am seeing similar problems trying to push to a local registry. Docker push on command line is working, so I know it isn't my creds or our local registry.

I've tried all 3 approaches specified in the README and get this:

  • Putting <username> and <password> tags into <configuration> works (yay!)
       <configuration>
          <repository>localhub.internal/library/centos7-oracle-java</repository>
          <username>me</username>
          <password>myself</password>
          <tag>${project.version}</tag>
        </configuration>
  • Using docker login HOST does not work (boo!)
       <configuration>
          <repository>localhub.internal/library/centos7-oracle-java</repository>
          <tag>${project.version}</tag>
        </configuration>
  • Using ~/.m2/settings.xml and <useMavenSettingsForAuth>true</useMavenSettingsForAuth> does not work (boo!)
       <configuration>
          <repository>localhub.internal/library/centos7-oracle-java</repository>
          <tag>${project.version}</tag>
          <useMavenSettingsForAuth>true</useMavenSettingsForAuth> 
        </configuration>

So if you haven't tried embedding your auth info into the pom.xml, try that. If you're using a recent version of Maven you can at least encrypt the password so it can't be re-used on other machines.

Well, I'm wrong about being able to encrypt the password in the pom file. Doesn't look like the password goes through maven's normal password handling code, so you have to put it in the pom.xml in clear text (boo!)

Also I figured out that the useMavenSettingsForAuth feature actually does work as long as you include your password in clear text in the settings.xml. I was testing with encrypted passwords initially.

I encountered similar problem with private registry. Any help ?

I've just spent five hours on this in conjunction with an internal Artifactory server configured to require an encrypted password. Unlike the OP, I am getting unauthorized: BAD_CREDENTIAL. This exception is what I get no matter what I try.

I can successfully use docker push from the command line while my ~/.docker/config.json has my base64 encoded encrypted password in it.

On the plus side, I am now running Artifactory with TLS enabled. I would really like to be able to use Maven to push my docker images, though.

Well grrr, of all the things I tried, I guess I never did put my credentials in the pom itself. So I can confirm that putting credentials, even encrypted, into the plugin configuration will let me push. That is patently the wrong way to handle this, though.

I give up. Artifactory gives me two usernames and four potential passwords. config.json uses email and base64 encrypted password. Turns out that this plugin wanted me to put my username (not email) and encrypted password (no base64).

I managed to get this to work by putting the credentials in settings.xml, however the clue was in this line:

[WARNING] Did not find maven server configuration for docker server docker.io

You have to specify the <id> to be docker.io

<server>
  <id>docker.io</id>
  <username>username</username>
  <password>password</password>
</server>

So I then set <useMavenSettingsForAuth>true</useMavenSettingsForAuth> in my POM

I can confirm the above is working. I created a new ~/.m2/settings.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers>
    <server>
      <id>docker.io</id>
      <username>mydockerhub_username</username>
      <password>mydockerhub_password</password>
    </server>
  </servers>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

And then had a pom file as follows:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mydomain</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>demo</name>
  <description>Demo project for Spring Boot</description>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
    <relativePath/>
    <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <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>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <version>1.3.7</version>
        <executions>
          <execution>
            <id>default</id>
            <goals>
              <goal>build</goal>
              <goal>push</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <repository>mydockerhub_username/springboothelloworld</repository>
          <tag>${project.version}</tag>
          <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
          <buildArgs>
            <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
          </buildArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I just thought it would be good to give complete files as examples.

@kenrachynski You mentioned encrypted password (no base64), how should the password be encrypted?

@xring As that's Artifactory specific, you log into your Artifactory server, go to your profile and unlock it. You'll see a block with your encrypted password for copying. Now, if the server does not have encryption enabled, you just use your regular password. Though I'd strongly suggest enabling all the security you have access to.

I use private repository and I had misleading and weird error message and it turned out, that it was the credential configuration problem.

Here the error:

[WARNING] Did not find maven server configuration for docker server artifactory-mycompany.com:10002
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.7:push (default-cli) on project myproject-jenkins: Could not push image: Request error: POST https://docker-mycompany.com:443/images/artifactory-mycompany.com:10002/myproject-jenkins/push?tag=2.0.2-SNAPSHOT: 500, body: {"message":"invalid character '\u009e' looking for beginning of value"}: HTTP 500 Internal Server Error -> [Help 1]

The solution (as stands in Readme.md):
reuse the repository url from plugin configuration section in pom.xml as id in settings.xml under server config:

e.g. in pom.xml you have <repository>artifactory-mycompany.com:10002/${project.name}</repository>
then in settings.xml you should have:

<servers>
  <server>
    <id>artifactory-mycompany.com:10002</id>
    <username>me</username>
    <password>mypassword</password>
  </server>
</servers>

encrypted passwords are now supported (see #167). Closing this as there are many issues wrapped together in this one and some or all may be resolved. Please open new issues if you still have problems.

I managed to get this to work by putting the credentials in settings.xml, however the clue was in this line:

[WARNING] Did not find maven server configuration for docker server docker.io

You have to specify the <id> to be docker.io

<server>
  <id>docker.io</id>
  <username>username</username>
  <password>password</password>
</server>

So I then set <useMavenSettingsForAuth>true</useMavenSettingsForAuth> in my POM

Thank you, It's working for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergiomazoodigeo picture sergiomazoodigeo  路  3Comments

bjornbak picture bjornbak  路  5Comments

Somebody25 picture Somebody25  路  9Comments

mmaeller picture mmaeller  路  10Comments

destebanm picture destebanm  路  8Comments