This is my very first try to create a Docker image and I'm hoping someone can help me out. My Dockerfile looks roughly like this:
FROM mybaseimage:0.1 MAINTAINER ... ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64 RUN sed 's/main$/main universe/' -i /etc/apt/sources.list ENV DEBIAN_FRONTEND noninteractive RUN apt-get update RUN apt-get install -y openjdk-7-jre && apt-get clean &&\ mkdir temp_dir && cd temp_dir && \ ${JAVA_HOME}/bin/jar -xvf somejar.jar &&\ cd .. ENTRYPOINT ["somescript.sh"]
Basically I'm only installing Java so I can expand a jar file. When I run my makefile I get the following error:
/bin/sh: 1: /usr/lib/jvm/java-7-openjdk-amd64: Permission denied
I've been trying to follow this example: https://registry.hub.docker.com/u/barnybug/openjdk-7-jre/dockerfile/
Edit: per request in the comment here is my makefile:
DOCKER_REGISTRY=registry.mycompany.com DOCKER_IMAGE=appimage-myapp DOCKER_TAG=3.0 SUDO= ARCHIVE_NAME=$(DOCKER_IMAGE):$(DOCKER_TAG) REPO_ARCHIVE_NAME=$(DOCKER_REGISTRY)/$(ARCHIVE_NAME) BASE_IMAGE_ARCHIVE=$(DOCKER_IMAGE)_$(DOCKER_TAG).tar.gz all: $(BASE_IMAGE_ARCHIVE) .PHONY: docker_image docker_image: Dockerfile $(SUDO) docker build -t $(ARCHIVE_NAME) . $(BASE_IMAGE_ARCHIVE): docker_image $(SUDO) docker tag -f $(ARCHIVE_NAME) $(REPO_ARCHIVE_NAME) $(SUDO) docker push $(REPO_ARCHIVE_NAME) $(SUDO) docker save $(ARCHIVE_NAME) | gzip -c > $@ $(SUDO) docker rmi $(REPO_ARCHIVE_NAME)
which I run with
make docker_image SUDO=sudo
Each Docker image must contain a JRE for the Spring Boot application to run. It is around 200 MB maximum. That means each docker image is, say 350 MB at the maximum. On the other hand, on my local PC I have only one JRE of 200 MB and each application takes only a few MB of space.
You can use the Java 11 image from hub.docker.com by typing the command :docker pull openjdk:tag on your machines terminal, where the tag is version of your intended java version. Or you can simply specify the image on your Dockerfile where FROM attribute must be the version of java.
The base image is the foundation of the new image you are about the build for your Java application.
I was able to install OpenJDK 8 via the steps below (taken from here). My Dockerfile inherits from phusion/baseimage-docker, which is based on Ubuntu 16.04 LTS.
# Install OpenJDK-8 RUN apt-get update && \ apt-get install -y openjdk-8-jdk && \ apt-get install -y ant && \ apt-get clean; # Fix certificate issues RUN apt-get update && \ apt-get install ca-certificates-java && \ apt-get clean && \ update-ca-certificates -f; # Setup JAVA_HOME -- useful for docker commandline ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/ RUN export JAVA_HOME
To install OpenJDK 7 instead, you may need to prepend
add-apt-repository ppa:openjdk-r/ppa
such that the first step becomes
# Install OpenJDK-7 RUN add-apt-repository ppa:openjdk-r/ppa && \ apt-get update && \ apt-get install -y openjdk-7-jdk && \ apt-get install -y ant && \ apt-get clean;
I hope this helps.
I was able to install Java-11 on an image using Ubuntu 18.04. I also just needed it for only one application. (The Python wrapper around Apache Tika.)
FROM python:3.8.2-buster COPY . /usr/src/app # Install OpenJDK-11 RUN apt-get update && \ apt-get install -y openjdk-11-jre-headless && \ apt-get clean; # Install PYTHON requirements COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # START WEBAPP SERVICE CMD [ "python", "/usr/src/app/main.py" ]
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With