Dockerfile
links
Supported tags and respective
What is Java?
Java is a concurrent, class-based, object-oriented language specifically designed to have as few implementation dependencies as possible. It is intended to allow application developers to "write once, run anywhere", meaning that code that runs on one platform does not need to be recompiled to run on another.
Java is a registered trademark of Oracle and/or its affiliates.
How to use this image
Start a Java instance in your app
The most straightforward way to use this image is to use a Java container as both the build and runtime environment. In your Dockerfile
, writing something along the lines of the following will compile and run your project:
FROM kratochj/oracle-java:8
COPY . /data
WORKDIR /data
RUN javac Main.java
CMD ["java", "Main"]
You can then run and build the Docker image:
docker build -t my-java-app .
docker run -it --rm --name my-running-app my-java-app
Compile your app inside the Docker container
There may be occasions where it is not appropriate to run your app inside a container. To compile, but not run your app inside the Docker instance, you can write something like:
docker run --rm -v "$PWD":/data -w /data java:7 javac Main.java
This will add your current directory as a volume to the container, set the working directory to the volume, and run the command javac Main.java
which will tell Java to compile the code in Main.java
and output the Java class file to Main.class
.
library/java?
What are the differences between this image and- Uses only dockerfile/alpine:3.4.
- Uses Oracle JDK instead of OpenJDK.
- Installs Java Cryptography Extension (JCE).
Alpine image
This image is based on the popular Alpine Linux project, available in the alpine
official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
This variant is highly recommended when final image size being as small as possible is desired. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.
To minimize image size, it's uncommon for additional related tools (such as git
or bash
) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine
image description for examples of how to install packages if you are unfamiliar).
License
View license information for the software contained in this image.