I've been trying to create an alpine-based docker image with Oracle Java (rather than openjdk). I have been specifically asked to create our own image here.
This is the Dockerfile I've come up with:
FROM alpine:3.6
RUN apk add --no-cache curl wget
RUN mkdir /opt/ && \
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie"\
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz && \
tar xvf jdk-8u131-linux-x64.tar.gz -C /opt/ && \
rm jdk-8u131-linux-x64.tar.gz && \
ln -s /opt/jdk1.8.0_131 /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin
RUN echo $JAVA_HOME && \
echo $PATH
RUN which java
RUN java -version
There are some unnecessary commands (like echoing the JAVA_HOME dir) which were added to help with debugging, but now I'm stuck: RUN which java returns /opt/jdk/bin/java as expected, but RUN java -version returns /bin/sh: java: not found.
I've tried a few things, including symlinking the executable(s) into /usr/bin, to no avail.
What am I missing?
EDIT:
Final output from docker is:
The command '/bin/sh -c java -version' returned a non-zero code: 127
Final edit:
Thanks to diginoise for putting me on to MUSL vs libc. I found adding the following to my Dockerfile allowed me to build a working image:
RUN apk --no-cache add ca-certificates && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
apk add glibc-2.25-r0.apk
Found at: https://github.com/sgerrand/alpine-pkg-glibc
You cannot achieve what you want
Alpine Linux uses MUSL as a Standard C library.
Oracle's Java for linux depends on GNU Standard C library (gclib).
Here is a bit more detailed info and official stance from Oracle on the topic
the JDK source code has not yet been ported to Alpine Linux, or more specifically, the musl C library. That is, it turns out that the thing about Alpine Linux that sticks out/is different from a JDK source code perspective is the C library.
The solution
If you looking for small Java Docker images, use OpenJDK ones.
openjdk:11-jre-slim image is only 77MB.
If you insist, on your head be it...
There is theoretical way, but it is not as trivial as you think.
You can find many examples of Alpine images running with OracleJDK like here or see expert's answer to this question as well.
They add the missing Standard GNU C library.
Be warned however...
All of these solutions could be in breach of Oracle's license agreement stating that the license is non-transferable, and the distributable is non-modifiable.
In the Dockerfiles you will find however:
Cookie: oraclelicense=accept-securebackup-cookie"
and many entries similar to
rm -rf ${JAVA_HOME}/*src.zip
For further details about legality of prepackaged Oracle's JRE or JDK Docker images see this article.
In case anyone needs fresh version of JDK I maintain Alpine Oracle JDK images https://hub.docker.com/r/expert/docker-java-minimal
Sources
https://github.com/unoexperto/docker-java-minimal/
I found an answer that works finally. All is needed is just the GlibC; huge thanks to S. Gerrand, this is such a big help.
Here's how to get the old JDK 8 running in Alpine 1.13:
FROM alpine:3.13
RUN apk --no-progress --purge --no-cache upgrade \
&& apk --no-progress --purge --no-cache add --upgrade \
curl \
wget \
openssh \
&& apk --no-progress --purge --no-cache upgrade \
&& rm -vrf /var/cache/apk/* \
&& curl --version
# Install vanilla GLibC: https://github.com/sgerrand/alpine-pkg-glibc
RUN curl -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -LO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk \
&& apk add glibc-2.32-r0.apk
RUN wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" \
http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz \
&& tar xvf jdk-8u131-linux-x64.tar.gz -C /opt \
&& rm jdk-8u131-linux-x64.tar.gz \
&& ln -s /opt/jdk1.8.0_131 /opt/jdk
ENV JAVA_HOME /opt/jdk
ENV PATH $PATH:/opt/jdk/bin
RUN echo $JAVA_HOME && \
echo $PATH
RUN which java
RUN java -version
ENTRYPOINT [ "java" ]
# To test run: docker run -t khalifahks/alpine-java -version
# docker export <container-id> | docker import - khalifahks/alpine-java:exported
# quick interative termnal: docker run -it --entrypoint=sh khalifahks/alpine-java sh
Related
my dockerfile for cloud run is as below.
FROM alpine:3.10.5
USER root
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools wheel \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi
WORKDIR /opt/bin
RUN pip install Flask 'gunicorn>=20.0.1,<21' sqlalchemy pg8000 logger
COPY <some jar files>.jar /opt/bin/
COPY *.py /opt/bin/
RUN rm -r /root/.cache
CMD exec gunicorn --bind :$PORT --workers 2 --threads 8 --worker-tmp-dir /dev/shm --timeout 30 http_test
when I run the docker image on cloudrun, i get the following error when I send a GET request to the URL given by Cloudrun:
020-05-04 13:22:14.551 ISTContainer Sandbox: Unsupported syscall membarrier(0x10,0x0,0x0,0x8,0x3e57651d89a0,0x3e57651d8a30). It is very likely that you can safely ignore this message and that this is not the cause of any error you might be troubleshooting. Please, refer to https://gvisor.dev/c/linux/amd64/membarrier for more information.
2020-05-04 13:22:14.603 ISTOpenJDK 64-Bit Server VM warning: Can't detect primordial thread stack location - find_vma failed
Have tried different alpine images, switched to gunicorn20.0.1 to avoid libc issues, no avail. Any suggestions, help would be much appreciated.
while deploying the docker image in cloud run change the Execution environment to the second generation
Second generation PREVIEW
File system access, full Linux compatibility, faster performance.
had the same issue and I have fixed it, Hope it helps.
I'm trying to install openjdk-8-jre vie DockerFile, as I build the docker images for my composer. But I'm hitting this error message.
Error message:
Package openjdk-8-jre-headless is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'openjdk-8-jre-headless' has no installation candidate
Here is the part from Dockerfile:
# Install openjdk and java cacerts
RUN apt-get update && apt-get install -y openjdk-8-jre-headless ca-certificates-java
If I install java directly from the console, by using exact same command without RUN, no problem with the package. But as I try installing it from the Dockerfile, I hit the error. I have understood that Docker uses same repos as the machine where docker is running? Ubuntu is version 16.04.
Or how I check available installation packages on Dockerfile? java - v gives an error..
Seems like you are using FROM python:3.8 as base and as mentioned by #masseyb in the comment under your question it does not have openjdk-8jre-headless package.
This may help you.
FROM python:3.7-alpine as base
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
RUN apk add --no-cache python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& rm -r /usr/lib/python*/ensurepip && \
if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
rm -r /root/.cache
RUN pip install --trusted-host pypi.python.org flask
This example Dockerfile can get you Java python and flask
I'm tasked with creating a very simple, web browser accessible gui that can run a specific java file within a docker container. To do this I've chosen to set up a php-apache server that serves an index.php document with the gui. The Dockerfile looks like this:
FROM php:7.0-apache
COPY src /var/www/html
EXPOSE 80
This gets the gui (index.php is inside the src folder) I've written up and running no problem, but it cannot access and run the required java files (obviously, since this creates a separate container).
The Question:
How can I set up a php-apache server inside the existing Dockerfile (provided below) doing the same thing as the Dockerfile above? My aim is to run the java file using php scripts and display the result to the user.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
I have not written the java file myself, only being tasked with running specific commands using it.
As it is Debian based images. one way of doing it, install packages in the container and create the new images from that.
root#310c94d8d75f:/usr/src/app# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
2: root#310c94d8d75f:/usr/src/app# apt update
3- root#310c94d8d75f:/usr/src/app# apt install apache2
4- root#310c94d8d75f:/usr/src/app# apt install php
finally run : docker commit
after this, you will get a new image with the mentioned name.
Ref: https://docs.docker.com/engine/reference/commandline/commit/
2: you can add the same command in Dockerfile and rebuild.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
RUN apt update && apt install apache2 -y && apt install php -y
There appears to be no easy way of merging images like I initially hoped (You cannot have multiple FROM statements in your Dockerfile). What I eventually ended up doing was to manually merge the two images (openjdk and php) into something like this:
FROM php:7.0-apache
ENV LANG C.UTF-8
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home
ENV JAVA_HOME /docker-java-home/jre
ENV JAVA_VERSION 8u212
ENV JAVA_DEBIAN_VERSION 8u212-b01-1~deb9u1
RUN set -ex; \
if [ ! -d /usr/share/man/man1 ]; then \
mkdir -p /usr/share/man/man1; \
fi; \
apt-get update; \
apt-get install -y --no-install-recommends openjdk-8-jre-headless="$JAVA_DEBIAN_VERSION"; \
rm -rf /var/lib/apt/lists/*; \
[ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \
update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \
update-alternatives --query java | grep -q 'Status: manual'
COPY ["./build/libs/*.jar", "./FooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
COPY gui/src /var/www/html
EXPOSE 80
Both are Debian based images so the merging were relatively easy (I also removed much of the cluttering comments from the original image source) and since the openjdk image were simpler, I added it on top of the php image instead of the other way around.
I've installed Android Studio 3.0 on VirtualBox, OS Lubuntu.
During making project, there is an exception:
Error:java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
Error:Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: java.lang.RuntimeException: No server to serve request. Check logs for details.
I've tried oracle-jdk8 and OpenJdk. The same promlem.
Not quite sure what your compile issue is, but regardless once you get past that you will more than likely run into the issue of not being able to run the Android Studio emulator with VirtualBox. Assuming you want to run the emulator my point being you may be wasting time trying to fix your issue. See the following old post Android emulator and virtualbox cannot run at same time.
Best to run Android Studio on your host machine.
I've been able to find the root cause: The error message means that Gradle cannot connect to some worker processes. In my case, the process was for 'aapt2'. Running 'ldd aapt2' indicated that some shared libraries were missing (mainly GLIBC). Since I'm using Docker based on Alpine Linux, it comes with a reduced GLIBC (glibc-musl). The solution was to simply install glibc.
Here is the complete Dockerfile for reference, although the missing libraries might be different for your distribution.
FROM openjdk:8-alpine
LABEL maintainer="Barry Lagerweij" \
maintainer.email="b.lagerweij#carepay.co.ke" \
description="Android Builder"
COPY android-packages /tmp/android-packages
RUN apk add --no-cache wget unzip ca-certificates \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub \
&& wget -q -O /tmp/glibc.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-2.26-r0.apk \
&& wget -q -O /tmp/glibc-bin.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.26-r0/glibc-bin-2.26-r0.apk \
&& apk add --no-cache /tmp/glibc.apk /tmp/glibc-bin.apk \
&& wget -q -O /tmp/android-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip \
&& mkdir -p /tmp/android-sdk/licenses \
&& unzip /tmp/android-tools.zip -d /tmp/android-sdk \
&& rm /tmp/android-tools.zip \
&& echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > /tmp/android-sdk/licenses/android-sdk-license \
&& echo "84831b9409646a918e30573bab4c9c91346d8abd" > /tmp/android-sdk/licenses/android-sdk-preview-license \
&& echo "d975f751698a77b662f1254ddbeed3901e976f5a" > /tmp/android-sdk/licenses/intel-android-extra-license \
&& mkdir ~/.android; echo "count=0" >> ~/.android/repositories.cfg \
&& /tmp/android-sdk/tools/bin/sdkmanager --package_file=/tmp/android-packages \
&& apk del wget unzip ca-certificates \
&& rm -rf /tmp/android-sdk/extras /tmp/android-sdk/tools/lib/x86 /tmp/android-sdk/tools/lib/monitor-* /tmp/glibc.apk /tmp/glibc-bin.apk /etc/apk/keys/sgerrand.rsa.pub
RUN mkdir /tmp/project \
&& echo "sdk.dir=/tmp/android-sdk" > /tmp/project/local.properties
ENV ANDROID_HOME /tmp/android-sdk
WORKDIR /tmp/project
I suggest you run 'ldd build-tools/26.0.2/aapt2' to see which libraries are missing from the OS.
I had this problem on lubuntu-32 bit. easiest solution is to use lubuntu-64 bit.
Here is my .gitlab-ci.yml script.
before_script:
- uname -a
- apt-get install default-jre default-jdk openjdk-7-jre openjdk-7-jdk
- java -version
- export MODE="service"
- export PID_FOLDER="/var/run/gitlab-runner-test"
dev:
script:
- chmod +x gradlew
- ./gradlew assembleDebug
I am trying to run the script on gitlab.com page to compile a android project. I checked with some alterations to my script that there is no java installed on the ci
linux Linux runner-8a2f473d-project-881036-concurrent-0 4.5.0-coreos-r1 #2 SMP Thu May 5 07:27:26 UTC 2016 x86_64 GNU/Linux.
I tried installing java, just like a sample which was shown for ruby, but it does not work, and gives an Unable to locate package error.
I am not sure what should be the package as it seems like a ubuntu system, but the command which works on my ubuntu does not work here.
This is not a local installation.
I believe you should be able to use the image feature described here. I found success with the anapsix/alpine-java:jdk8 Docker image.
I am using my own Docker gitlab-runner with a custom Docker image as I need Maven with Oracle java. I'm not 100% on if the shared runner on gitlab.com allows you to use your own image.
My Dockerfile for that (which I upload to Gitlab and use their new Docker container register feature)
FROM anapsix/alpine-java:jdk8
ENV MAVEN_VERSION 3.3.3
RUN apk update && apk upgrade && apk add curl wget bash tar rsync openssh-client
RUN mkdir -p /usr/share/maven \
&& curl -fsSL http://apache.osuosl.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn \
&& rm -rf /tmp/* /var/cache/apk/*;
ENV MAVEN_HOME /usr/share/maven
ENTRYPOINT []
CMD ["bash"]