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
- Host: GitHub
- URL: https://github.com/otaviojava/hello-world-docker
- Owner: otaviojava
- License: apache-2.0
- Created: 2019-05-11T19:16:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-16T19:12:29.000Z (almost 7 years ago)
- Last Synced: 2024-12-30T05:29:16.596Z (about 1 year ago)
- Language: Java
- Size: 32.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.asciidoc
- License: LICENSE
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
----