docker-maven-plugin
docker-maven-plugin copied to clipboard
How to actually get verbose output from docker:build?
We are using v0.44 of docker-maven-plugin. I was working on this a few days ago, and I saw that we were getting verbose output, where it would show what tag was being applied to the image, but for some reason we get almost nothing in the output. I've set "verbose=true" several different ways now, and it doesn't make any difference.
Our current plugin block looks like this:
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.44.0</version>
<configuration>
<verbose>true</verbose>
<imageName>${docker.registry}/<stuff>/${serviceArtifactName}:${docker.image.tag}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<serverId>docker-hub</serverId>
<registryUrl>https://${docker.registry}</registryUrl>
<forceTags>true</forceTags>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>opt/ajsc/etc/config/*</include>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>prometheus-javaagent.jar</include>
</resource>
</resources>
</configuration>
</plugin>
When the build runs, we get almost nothing as I said, just this:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.172 s
[INFO] Finished at: 2024-02-26T23:28:07Z
[INFO] ------------------------------------------------------------------------
@davidmichaelkarr : You should be able to see fully qualified image name when you do a docker:build, this is logged when in normal build without verbose options enabled:
mvn docker:build
docker:0.45-SNAPSHOT:build (default-cli) @ dmp-build-arg-regression ---
[INFO] Building tar: /home/rokumar/work/repos/dmp-testing/dmp-build-arg-regression/target/docker/myimage/21/tmp/docker-build.tar
[INFO] DOCKER> [myimage:21]: Created docker-build.tar in 33 milliseconds
[INFO] DOCKER> [myimage:21]: Built image sha256:07911
[INFO] ------------------------------------------------------------------------
In above case image name is myimage:21 where tag is 21.
If you specify build in verbose option, you will be able to see docker build output:
$ mvn docker:build -Ddocker.verbose=build
[INFO] --- docker:0.45-SNAPSHOT:build (default-cli) @ dmp-build-arg-regression ---
[INFO] Building tar: /home/rokumar/work/repos/dmp-testing/dmp-build-arg-regression/target/docker/myimage/21/tmp/docker-build.tar
[INFO] DOCKER> [myimage:21]: Created docker-build.tar in 33 milliseconds
[INFO] DOCKER> Step 1/2 : ARG FROM_IMAGE
[INFO] DOCKER>
[INFO] DOCKER> Step 2/2 : FROM ${FROM_IMAGE} AS jlink
[INFO] DOCKER>
[INFO] DOCKER> ---> 079114de2be1
[INFO] DOCKER> Successfully built 079114de2be1
[INFO] DOCKER> Successfully tagged myimage:21
[INFO] DOCKER> [myimage:21]: Built image sha256:07911
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.398 s
[INFO] Finished at: 2024-02-27T11:05:53+05:30
[INFO] ------------------------------------------------------------------------
If you specify api in verbose option, you will be able to see Docker API endpoints being hit:
$ mvn docker:build -Ddocker.verbose=api
[INFO] --- docker:0.45-SNAPSHOT:build (default-cli) @ dmp-build-arg-regression ---
[INFO] DOCKER> GET unix://127.0.0.1:1/version
[INFO] Building tar: /home/rokumar/work/repos/dmp-testing/dmp-build-arg-regression/target/docker/myimage/21/tmp/docker-build.tar
[INFO] DOCKER> [myimage:21]: Created docker-build.tar in 32 milliseconds
[INFO] DOCKER> GET unix://127.0.0.1:1/v1.44/images/openjdk%3A21/json
[INFO] DOCKER> GET unix://127.0.0.1:1/v1.44/images/openjdk%3A21/json
[INFO] DOCKER> GET unix://127.0.0.1:1/v1.44/images/openjdk%3A21/json
[INFO] DOCKER> GET unix://127.0.0.1:1/v1.44/images/myimage%3A21/json
[INFO] DOCKER> POST to unix://127.0.0.1:1/v1.44/build?buildargs=%7B%22FROM_IMAGE%22%3A%22openjdk%3A21%22%7D&dockerfile=Dockerfile&forcerm=1&nocache=0&squash=0&t=myimage%3A21 with contents of file /home/rokumar/work/repos/dmp-testing/dmp-build-arg-regression/target/docker/myimage/21/tmp/docker-build.tar
[INFO] DOCKER> GET unix://127.0.0.1:1/v1.44/images/myimage%3A21/json
[INFO] DOCKER> [myimage:21]: Built image sha256:07911
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I'm getting nothing from all those variations. I think this must mean that the plugin is finding nothing to do. I don't know why that would be, but I would have to guess that it's not seeing a Dockerfile. Would the plugin print no output if that happened? We'll look closely at the config later today.
@davidmichaelkarr : I'm not able to see any image configuration in your plugin configuration. Could you please try adding this in plugin configuration?
<images>
<image>
<name>your-registry.org/yourusername/yourimagename:tag</name>
<build>
<dockerFile>Dockerfile</dockerFile>
</build>
</image>
</images>
By default plugin would automatically detect Dockerfile if it is placed in project root directory.
Could you please check our dockerfile sample project to see how it's different from your project?
OK. Would this look better (untested)?
<images>
<image>
<name>imagenamewithtag</name>
<build>
<contextDir>${project.basedir}/src/main/docker</contextDir>
</build>
</image>
</images>
It should work given your Dockerfile has correct references as per your configured docker context directory.
It looks like the name can't have the tag, so we're adding a tags block.
default tag is added after : in the image <name> block, something like this:
<name>yourimagename:yourtag</name>
Well, we we were trying to have "yourtag" reference a property, like "${docker.image.tag}". That gets a syntax error. Fortunately, we are were able to do this with a tags block.