Skip to content

Instantly share code, notes, and snippets.

@carlosjgp
Last active July 24, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosjgp/ce6469f1ef71157c4deec21882186281 to your computer and use it in GitHub Desktop.
Save carlosjgp/ce6469f1ef71157c4deec21882186281 to your computer and use it in GitHub Desktop.
[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