Closed h33x0 closed 4 years ago
+1
+1
+1
+1
+1
+1
+1
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
+1
Can this be re-opened? It's a pretty significant issue when you're leveraging custom base images.
For those still having this issue, there's a way to "fix" this problem using the settings.xml
file. Here's how :
Instead of using your command as follows
mvn [...] -Ddockerfile.username=[...] -Ddockerfile.password=[...]
Use this in Unix shell
DOCKERFILE_USERNAME=[...] DOCKERFILE_PASSWORD=[...] mvn [...]
Or this in Windows CMD
set DOCKERFILE_USERNAME=[...]
set DOCKERFILE_PASSWORD=[...]
mvn [...]
# Optional, to unset the variables after using them
set DOCKERFILE_USERNAME=
set DOCKERFILE_PASSWORD=
In dockerfile-maven-plugin
configuration in the pom.xml
, useMavenSettingsForAuth
must be set to true
(or use -Ddockerfile.useMavenSettingsForAuth=true
on your command line).
Your settings.xml
should contain the following
<servers>
<!-- .... -->
<server>
<id>REPLACE THIS BY YOUR DOCKER REPOSITORY</id>
<username>${env.DOCKERFILE_USERNAME}</username>
<password>${env.DOCKERFILE_PASSWORD}</password>
</server>
<!-- .... -->
</servers>
Maven will replace the environment variables in the settings.xml
and your Docker build/push should succeed using this maven plugin.
Description
If FROM image stored on private repo and using on build
-Ddockerfile.username=... -Ddockerfile.password=...
flags (otherwise - same parameters on<configuration>
section) build fails with "Could not build image"If run build with -Ddockerfile.useMavenSettingsForAuth=true flag (and server record on settings.xml) - build success.
How to reproduce
-Ddockerfile.username=... -Ddockerfile.password=...
build flagsWhat do you expect
Source image downloaded, build success.
What happened instead
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (build) on project sample-project: Could not build image: Get https://<private-registry>/v2/images/docker-images/openjdk-11/manifests/latest: denied: access forbidden -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.13:build (build) on project sample-project: Could not build image
Software:
docker version
: 19.03.1Full backtrace