An open API service indexing awesome lists of open source software.

https://github.com/otaviojava/hello-world-docker

A Hello world docker with Java
https://github.com/otaviojava/hello-world-docker

Last synced: 8 months ago
JSON representation

A Hello world docker with Java

Awesome Lists containing this project

README

          

== Hello World with Docker

[source,bash]
----
mvn clean package
java -cp target/hello-world-docker-1.0-SNAPSHOT.jar App
----

[source,bash]
----
docker container run -it openjdk:8
root@bd2947d4d562:/# java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)
root@bd2947d4d562:/# exit
exit
----

Create a new Dockerfile and use the following content:

[source,Dockerfile]
----
FROM openjdk:8
COPY target/docker-1.0-SNAPSHOT.jar /usr/src/docker-1.0-SNAPSHOT.jar
CMD java -cp /usr/src/docker-1.0-SNAPSHOT.jar App
----

Build the image:

[source,bash]
----
docker image build -t hello-world-docker-java:latest .
----

Run the image:

[source,bash]
----
docker container run hello-world-docker-java:latest
----

Set the maven plugin:

[source,bash]
----
mvn clean package docker:build
----

== Docker War

Set the maven plugin:

[source,bash]
----
mvn clean package docker:build
----

Run the image:

[source,bash]
----
docker container run -p 8080:8080 -e JAVA_OPTS='-Xmx100m' hello-world-java-war
----

To Test:

[source,bash]
----
curl -X GET http://localhost:8080/hello-world/resource/hello
----

== Docker Uber Jar

[source,bash]
----
mvn clean install tomee:exec docker:build
----

[source,bash]
----
docker container run -p 8080:8080 -e JAVA_OPTS='-Xmx100m' hello-world-uber-jar
----

To Test:

[source,bash]
----
curl -X GET http://localhost:8080/hello-world/resource/hello
----

== Docker Compose

Server Up

[source,bash]
----
docker-compose up -d
----

Test it:

[source,bash]
----
curl -X GET http://localhost/hello-world/resource/hello
----

Server Down

[source,bash]
----
docker-compose down
----