Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Spring Boot] Docker compose
docker run -P com.example/demo && docker ps
docker run -p 8080:8080 com.example/demo
FROM anapsix/alpine-java
EXPOSE 8080
ADD target.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
<project>
<properties>
...
<!-- Docker properties -->
<docker.plugin.version>0.4.10</docker.plugin.version>
<docker.image.prefix>${project.groupId}</docker.image.prefix>
<docker.image.name>${docker.image.prefix}/${project.artifactId}</docker.image.name>
...
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<configuration>
<imageName>${docker.image.name}</imageName>
<dockerDirectory>docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-image</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<image>${docker.image.name}</image>
<newName>${docker.image.name}:${project.version}</newName>
</configuration>
</execution>
<execution>
<id>push-image</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</project>
mvn clean package && docker run -p 8080:8080 com.example/demo
<project>
...
<build>
<!-- Generic name for all the JARs -->
<finalName>target</finalName>
...
</build>
...
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment