Sign inSign up

lonly/docker-alpine-java

By lonly

•Updated almost 9 years ago

Basic Docker image to run Java applications.

Image
1

374

lonly/docker-alpine-java repository overview

⁠docker-alpine-java

Basic Docker image to run Java applications.

  • oraclejre-8u152

⁠Introduction

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. The main caveat to note is that it does use musl libc instead of glibc and friends, so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice. 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).

Also, JRE bundle contains lots of unnecessary for Docker image stuff, so it was cleaned up.

⁠Build

docker build \
--rm \
-t lonly/docker-alpine-java:oraclejre-8u152 \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` .

⁠Usage

This image could be a base image for your projects, so you may use it like this:

FROM lonly/docker-alpine-java:oraclejdk-8u152

COPY ./my_app /usr/local/bin/my_app
docker build -t my_app .

⁠Test

echo 'public class Main { public static void main(String[] args) { System.out.println("Hello World"); } }' > Main.java
docker run --rm -v "$(pwd)":/mnt --workdir /mnt ldocker-alpine-java:oraclejre-8u152 sh -c "javac Main.java && java Main"

Tag summary

Content type

Image

Digest

Size

69.8 MB

Last updated

almost 9 years ago

docker pull lonly/docker-alpine-java