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:
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?
I ended up building the docker image by myself without the plugin:
And my Dockefile (has been renamed):
I then run it like so:
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:
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/
fixed this in windows 10 by:
Important are these two tags:
I am using a dockerfile, which path you have to define with this tag:
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: