GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - krishnak366/docker-java-hello-world: Simple getting started example of building and running Java containers without installing Java.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
Dockerfile-8u131
Dockerfile-8u131
 
 
Dockerfile-9b170
Dockerfile-9b170
 
 
HelloWorld.java
HelloWorld.java
 
 
Readme.md
Readme.md
 
 

Repository files navigation

This project provides a simple example of using Docker containers to build and run a Java application without installing Java. The sample is referenced in the DZone article Containers are the new Build Artifact.

This sample does not use the Smartsheet API.

Compile Java Class

When building a Java application we need a Java Development Kit (JDK). We can use an existing Docker image with a JDK in it to build our class.

docker run -it -v $(pwd):/build openjdk:8u131-jdk-alpine javac /build/HelloWorld.java

Build Docker Container Image

We can then take our Java class file (aka our build artifact) and bundle it into a container image.

docker build -t hello-world:8u131 -f Dockerfile-8u131 .

Run Container

Once we have a compiled Java class we can simply execute it with a Java Runtime Environment (JRE).

docker run -it --rm=true hello-world:8u131

Build and Run Container with Java 9

Let's assume we also want to run our Java class in a Java 9 environment to test it. We can easily take the same artifact (our HelloWorld.class file) that was compiled with Java 8u131 and run it in a Java 9 container. We use a different Dockerfile which specifies the Java 9 JVM as the base image. Then we build it and tag it so we have both the Java 8 and Java 9 images to run either.

docker build -t hello-world:9b170 -f Dockerfile-9b170 .
docker run -it --rm=true hello-world:9b170

About

Simple getting started example of building and running Java containers without installing Java.

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.