Spring boot with docker unable to find valid certification path to requested target error

I’m using spring boot and am trying to set it up with Docker. I’ve tried everything I could find on google and nothing seems to get me going. I’m running

 mvn clean package docker:build 

Running this will do the spring-boot tests, run DB migrations, build the JAR, and then when it comes to Building the Docker image, I get the following error:

  • docker run container happens error when mapped the container's port with machine
  • Docker Volume another disk
  • Dokku recognizes my Node.js app as Go app on deploy
  • Error when test chaincode_example02.go in docker
  • Docker on Amazon Linux AMI
  • Docker Swarm - strategy doesn't seem to have any effect
  • Failed to execute goal com.spotify:docker-maven-plugin:0.4.9:build (default-cli) 
    on project app: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: javax.net.ssl.SSLHandshakeException: 
    sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: 
    unable to find valid certification path to requested target -> [Help 1]
    

    Here is the Dockerfile I’m using:

    FROM java:8-jdk
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/Users/james/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    EXPOSE 8080
    VOLUME /tmp
    ADD app-0.0.1-SNAPSHOT.jar app.jar
    RUN sh -c 'touch /app.jar'
    ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
    

    And here is my docker-maven-plugin configuration:

     ... pom stuff
    <docker.image.prefix>jamesone1</docker.image.prefix>
        ... other pom stufff
    <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.9</version>
        <configuration>
                <dockerHost>https://192.168.99.100:2376</dockerHost>
                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                <dockerDirectory>src/main/docker</dockerDirectory>
    
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
        </configuration>
    </plugin>
    

    I’m using the dock for mac & am using a docker-machine with the following env:

    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/Users/james/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    

    What’s going on?! Am I missing something?

  • Can docker services only be attached to docker overlay networks?
  • How to pass docker run command line arg to docker-compose?
  • Docker swarm and service discovery
  • Run multiple docker-compose (one per machine)
  • Mean app in Docker Containar
  • boot2docker can't access the outside world
  • 2 Solutions collect form web for “Spring boot with docker unable to find valid certification path to requested target error”

    fixed this in windows 10 by:

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <imageName>yourImageName</imageName>
                    <dockerDirectory>src/main/docker</dockerDirectory>
                    <dockerHost>https://192.168.99.100:2376</dockerHost>
                    <dockerCertPath>/Users/your_user/.docker/machine/machines/default</dockerCertPath>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>
    

    Important are these two tags:

    <dockerHost>https://192.168.99.100:2376</dockerHost>
    <dockerCertPath>/Users/your_user/.docker/machine/machines/default</dockerCertPath>
    

    I am using a dockerfile, which path you have to define with this tag:

    <dockerDirectory>src/main/docker</dockerDirectory>  
    

    Now you can build your jar and generate docker image via:

    mvn package docker:build

    I think on mac just follwing value has to be different:

    <dockerCertPath>/Users/your_user/.docker/machine/machines/default</dockerCertPath>
    

    I ended up building the docker image by myself without the plugin:

    docker build -f Dockefile .
    

    And my Dockefile (has been renamed):

    FROM java:8-jdk
    EXPOSE 8080
    #VOLUME /tmp
    
    ADD target/app-0.0.1-SNAPSHOT.jar /opt/demo/app-0.0.1-SNAPSHOT.jar
    CMD ["java","-jar","/opt/demo/app-0.0.1-SNAPSHOT.jar"]
    

    I then run it like so:

     docker run <container id here>
    

    I just couldn’t get the mvn plugin to work!

    Edit

    Furthermore I ended up creating a docker-compose.yml which makes things a lot simpler!!!

    You define properties such as the ports you want open, dockerfile location, and run docker-compose, and it’ll magically build+run the docker image!

    Example docker-compose.yml that I’m using:

    version: '2'
    services:
      web:
        build: .
        ports:
         - "8080:8080"
    

    build references the Dockerfile location. *Note you may need to the Dockerfile+yml file to be in the same location!

    ports reference the ports I want open. Now I can goto localhost:8080 and my request will be forwarded to the docker container.

    Read more on docker container here:

    https://docs.docker.com/compose/gettingstarted/

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.