Search code examples
springspring-bootcontainerscloudgcloud

Maven Docker issue Java Spring Boot Failed to execute goal io.fabric8:docker-maven-plugin


I'm trying to create a Spring-boot container, but i'm having some trouble with it:

This is the error i'm getting on a compute-engine vm on gcloud running Debian.

The command i ran is

maven clean install

I have tried google searching these issues, but most of the answers are related to an improper installation of docker, which is not the case:

Running the docker hello-world example worked, and i'm unsure what the problem is.

[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dockboot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /home/jeffpascal96/docker_boot/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dockboot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/jeffpascal96/docker_boot/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dockboot ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ dockboot ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ dockboot ---
[INFO] Building jar: /home/jeffpascal96/docker_boot/target/dockboot-0.2-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.13.RELEASE:repackage (default) @ dockboot ---
[INFO] 
[INFO] --- docker-maven-plugin:0.31.0:build (build-docker-image) @ dockboot ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] Total time: 13.392 s
[INFO] Finished at: 2019-09-15T11:46:23+00:00
[INFO] Final Memory: 32M/78M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.31.0:build (build-docker-image) on project dockboot
: Execution build-docker-image of goal io.fabric8:docker-maven-plugin:0.31.0:build failed: No <dockerHost> given, n
o DOCKER_HOST environment variable, no read/writable '/var/run/docker.sock' or '//./pipe/docker_engine' and no exte
rnal provider like Docker machine configured -> [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/PluginExecutionException

pom.xml:

<?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>javatechy</groupId>
        <artifactId>dockboot</artifactId>
        <version>0.2-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>dockboot</name>
        <description>Demo project for Dockerized Spring boot</description>
        <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.5.13.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>
                <docker.registry>javatechy</docker.registry>
        </properties>
        <scm>
                <connection>scm:git:https://[email protected]/javatechy/docker_boot.git</connection>
                <developerConnection>scm:git:https://[email protected]/javatechy/docker_boot.git</developerConne
ction>
                <tag>HEAD</tag>
        </scm>
        <dependencies>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-actuator</artifactId>
                </dependency>
                <dependency>

Dockerfile

FROM javatechy/openjdk-8-slim
MAINTAINER Deepak Kumar <[email protected]>
ENV ENV_NAME local
ENV BOOTAPP_JAVA_OPTS -Xms256m -Xmx256m
ENV LOG_PATH "/var/log/casa"
ENV BOOTAPP_USR="root" BOOTAPP_GROUP="root" BOOTAPP_PATH="/app.jar"
ENV SERVER_PORT 8000
EXPOSE $SERVER_PORT
COPY wrapper.sh /wrapper.sh
RUN chmod 555 /wrapper.sh
USER root
COPY maven/app.jar $BOOTAPP_PATH
RUN chmod 555 $BOOTAPP_PATH && \
            touch $BOOTAPP_PATH
RUN mkdir $LOG_PATH            
RUN chmod 777 $LOG_PATH && touch $LOG_PATH 
USER $BOOTAPP_USR
# RUN cat ./newrelic/newrelic.yml | sed -e 's/app_name:.*/app_name: docker_boot/' > ./newrelic/newrelic.yml

ENTRYPOINT ["/wrapper.sh"]
#!/usr/bin/env bash
exec java -javaagent:./newrelic/newrelic.jar -Djava.security.egd=file:/dev/./urandom $BOOTAPP_JAVA_OPTS -jar -Dspri
ng.profiles.active=$ENV_NAME $BOOTAPP_PATH --server.port=$SERVER_PORT > /dev/stdout 2>&1

Solution

  • If you are new to Creating docker images using spring boot I recommend using JIB plugin as opposed to spotify/docker-maven-plugin (now inactive), spotify/dockerfile-maven, JIB, boost-maven-plugin (Spring Boot-focused), fabric8io/docker-maven-plugin.

    According to Google Cloud's announcement :

    "Jib is a fast and simple container image builder that handles all the steps of packaging your application into a container image. It does not require you to write a Dockerfile or have docker installed, and it is directly integrated into Maven and Gradle — just add the plugin to your build and you’ll have your Java application containerized in no time."