In continuation to question, below is the updated docker file:
FROM microsoft/aspnetcore-build:1.0.1
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE 1
# This is FROM openjdk:8-jdk
RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
unzip \
xz-utils \
apt-transport-https \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get install -y --no-install-recommends apt-transport-https ca-certificates
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys AA8E81B4331F7F50
# RUN echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list
RUN echo 'deb http://archive.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list
RUN echo 'deb https://apt.dockerproject.org/repo debian-jessie main' > /etc/apt/sources.list.d/docker.list
RUN echo "Acquire::Check-Valid-Until \"false\";" > /etc/apt/apt.conf.d/100disablechecks
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
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
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
# ENV JAVA_VERSION 8u111
# ENV JAVA_DEBIAN_VERSION 8u111-b14-2~bpo8+1
# ENV JAVA_VERSION 8u222
# ENV JAVA_DEBIAN_VERSION 8u222-b10-1ubuntu1~18.04.1
ENV JAVA_VERSION 8u171
ENV JAVA_DEBIAN_VERSION 8u171-b11-1~bpo8+1
# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
ENV CA_CERTIFICATES_JAVA_VERSION 20140324
RUN set -x \
&& apt-get update \
&& apt-get install -y \
openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
&& rm -rf /var/lib/apt/lists/* \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
# see CA_CERTIFICATES_JAVA_VERSION notes above
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure
##### END OF THE JDK
##### START Jenkins Slave Node Config settings
# Create Jenkins User
RUN useradd jenkins -m -s /bin/bash
RUN chown -R jenkins /home/jenkins
RUN chgrp -R jenkins /home/jenkins
RUN chown -R jenkins /tmp
RUN chgrp -R jenkins /tmp
# Add the jenkins user to sudoers
RUN echo "jenkins ALL=(ALL) ALL" >> etc/sudoers
# Must install docker to create docker images from docker container. Inception. Head... hurts.
# container must be called with -v /var/run/docker.sock:/var/run/docker.sock
RUN apt-get update && apt-get install -y --no-install-recommends \
docker-engine \
&& rm -rf /var/lib/apt/lists/*
# This must run after the docker install
RUN gpasswd -a jenkins docker
USER jenkins
Below is the error:
Step 16/26 : RUN set -x && apt-get update && apt-get install -y openjdk-8-jdk="$JAVA_DEBIAN_VERSION" ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" && rm -rf /var/lib/apt/lists/* && [ "$JAVA_HOME" = "$(docker-java-home)" ]
---> Running in 6d823a145982
+ apt-get update
Get:1 https://apt.dockerproject.org debian-jessie InRelease [48.7 kB]
Get:2 http://archive.debian.org jessie-backports InRelease [166 kB]
Get:3 https://apt.dockerproject.org debian-jessie/main amd64 Packages [7366 B]
Get:4 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://deb.debian.org jessie InRelease
Get:5 http://deb.debian.org jessie-updates InRelease [16.3 kB]
Get:6 http://archive.debian.org jessie-backports/main amd64 Packages [1171 kB]
Get:7 http://deb.debian.org jessie Release.gpg [1652 B]
Get:8 http://deb.debian.org jessie Release [77.3 kB]
Get:9 http://security.debian.org jessie/updates/main amd64 Packages [892 kB]
Get:10 http://deb.debian.org jessie-updates/main amd64 Packages [20 B]
Get:11 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Fetched 11.5 MB in 14s (803 kB/s)
Reading package lists...
+ apt-get install -y openjdk-8-jdk=8u171-b11-1~bpo8+1 ca-certificates-java=20140324
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
openjdk-8-jdk : Depends: openjdk-8-jre (= 8u171-b11-1~bpo8+1) but it is not going to be installed
Depends: openjdk-8-jdk-headless (= 8u171-b11-1~bpo8+1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
ERROR: Service 'slavedotnet' failed to build: The command '/bin/sh -c set -x && apt-get update && apt-get install -y openjdk-8-jdk="$JAVA_DEBIAN_VERSION" ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" && rm -rf /var/lib/apt/lists/* && [ "$JAVA_HOME" = "$(docker-java-home)" ]' returned a non-zero code: 100
How to resolve this version issue?
See this:
The backports repository is deactivated by default. So, if you want to install a backported package, you will have to state that explicitly.
For example:
debian:/home/human# aptitude -t buster-backports install cockpit
So, for your case, you need to change to next:
apt-get install -t jessie-backports -y \
openjdk-8-jdk \
ca-certificates-java \
Here, I suggest you don't add version selection for package like next:
openjdk-8-jdk="$JAVA_DEBIAN_VERSION"
Because, default it will choose the latest version in this os release apt repo. If you insist, then for backports repo, you need to separate install them:
apt-get install -t jessie-backports -y \
openjdk-8-jdk="$JAVA_DEBIAN_VERSION" && \
apt-get install -t jessie-backports -y \
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
Below command:
FROM microsoft/aspnetcore-build:1.0.1
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE 1
# This is FROM openjdk:8-jdk
RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
unzip \
xz-utils \
apt-transport-https \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get install -y --no-install-recommends apt-transport-https ca-certificates
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys AA8E81B4331F7F50
# RUN echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list
RUN echo 'deb http://archive.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list
RUN echo 'deb https://apt.dockerproject.org/repo debian-jessie main' > /etc/apt/sources.list.d/docker.list
RUN echo "Acquire::Check-Valid-Until \"false\";" > /etc/apt/apt.conf.d/100disablechecks
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
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
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
# ENV JAVA_VERSION 8u111
# ENV JAVA_DEBIAN_VERSION 8u111-b14-2~bpo8+1
ENV JAVA_VERSION 8u171
ENV JAVA_DEBIAN_VERSION 8u171-b11-1~bpo8+1
# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
ENV CA_CERTIFICATES_JAVA_VERSION 20140324
# RUN set -x \
# && apt-get update \
# && apt-get install -y \
# openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
# ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
# && rm -rf /var/lib/apt/lists/* \
# && [ "$JAVA_HOME" = "$(docker-java-home)" ]
RUN set -x \
&& apt-get update \
&& apt-get install -y openjdk-8-jre-headless ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
&& apt-get install -y openjdk-8-jre-headless \
openjdk-8-jdk-headless \
openjdk-8-jre \
openjdk-8-jdk \
# ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
&& rm -rf /var/lib/apt/lists/* \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
# see CA_CERTIFICATES_JAVA_VERSION notes above
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure
##### END OF THE JDK
##### START Jenkins Slave Node Config settings
# Create Jenkins User
RUN useradd jenkins -m -s /bin/bash
RUN chown -R jenkins /home/jenkins
RUN chgrp -R jenkins /home/jenkins
RUN chown -R jenkins /tmp
RUN chgrp -R jenkins /tmp
# Add the jenkins user to sudoers
RUN echo "jenkins ALL=(ALL) ALL" >> etc/sudoers
# Must install docker to create docker images from docker container. Inception. Head... hurts.
# container must be called with -v /var/run/docker.sock:/var/run/docker.sock
RUN apt-get update && apt-get install -y --no-install-recommends \
docker-engine \
&& rm -rf /var/lib/apt/lists/*
# This must run after the docker install
RUN gpasswd -a jenkins docker
USER jenkins
gives error:
Step 16/26 : RUN set -x && apt-get update && apt-get install -y openjdk-8-jre-headless ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" && apt-get install -y openjdk-8-jre-headless openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jdk && rm -rf /var/lib/apt/lists/* && [ "$JAVA_HOME" = "$(docker-java-home)" ]
---> Running in 3733400f9098
+ apt-get update
Get:1 https://apt.dockerproject.org debian-jessie InRelease [48.7 kB]
Get:2 http://archive.debian.org jessie-backports InRelease [166 kB]
Ign http://deb.debian.org jessie InRelease
Get:3 http://deb.debian.org jessie-updates InRelease [16.3 kB]
Get:4 http://security.debian.org jessie/updates InRelease [44.9 kB]
Get:5 http://deb.debian.org jessie Release.gpg [1652 B]
Get:6 http://deb.debian.org jessie Release [77.3 kB]
Get:7 https://apt.dockerproject.org debian-jessie/main amd64 Packages [7366 B]
Get:8 http://archive.debian.org jessie-backports/main amd64 Packages [1171 kB]
Get:9 http://deb.debian.org jessie-updates/main amd64 Packages [20 B]
Get:10 http://deb.debian.org jessie/main amd64 Packages [9098 kB]
Get:11 http://security.debian.org jessie/updates/main amd64 Packages [892 kB]
Fetched 11.5 MB in 14s (818 kB/s)
Reading package lists...
+ apt-get install -y openjdk-8-jre-headless ca-certificates-java=20140324
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
openjdk-8-jre-headless : Breaks: ca-certificates-java (< 20160321~) but 20140324 is to be installed
E: Unable to correct problems, you have held broken packages.
ERROR: Service 'slavedotnet' failed to build: The command '/bin/sh -c set -x && apt-get update && apt-get install -y openjdk-8-jre-headless ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" && apt-get install -y openjdk-8-jre-headless openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jdk && rm -rf /var/lib/apt/lists/* && [ "$JAVA_HOME" = "$(docker-java-home)" ]' returned a non-zero code: 100
How to resolve the certificate dependency?
Been slamming this docker config file for a few hours now and am starting to conclude this is impossible. Help me change my mind!
I'm trying to install open-jdk in a docker image like so:
FROM php:7.1-apache-stretch
# NOTE: We cannot upgrade to 7.2+ until we remove all uses of mcrypt. It
is officially removed.
RUN echo 'deb http://deb.debian.org/debian stretch-backports main' >
/etc/apt/sources.list.d/backports.list
RUN apt-get update
RUN apt-get install -y stretch-backports
RUN apt-get install -y default-jdk-headless ca-certificates-java
And get the following error:
E: Unable to locate package stretch-backports
ERROR: Service 'app' failed to build: The command '/bin/sh -c apt-get
install -y stretch-backports' returned a non-zero code: 100
Success! I was able to resolve by following this:
https://assertnull.com/installing-java-in-docker-php/
Here's my dockerfile now:
FROM php:7.1-apache-stretch
# NOTE: We cannot upgrade to 7.2+ until we remove all uses of mcrypt. It is officially removed.
# Hack for debian-slim to make the jdk install work below.
RUN mkdir -p /usr/share/man/man1
# repo needed for jdk install below.
RUN echo 'deb http://deb.debian.org/debian stretch-backports main' > /etc/apt/sources.list.d/backports.list
# Update image & install application dependant packages.
RUN apt-get update && apt-get install -y \
nano \
libxext6 \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libmcrypt-dev \
libxslt-dev \
libpcre3-dev \
libxrender1 \
libfontconfig \
uuid-dev \
ghostscript \
curl \
wget \
ca-certificates-java
RUN apt-get -t stretch-backports install -y default-jdk-headless
I need both java and python in my docker container to run some code.
This is my dockerfile:
It works perpectly if I don't add the FROM openjdk:slim
#get python
FROM python:3.6-slim
RUN pip install --trusted-host pypi.python.org flask
#get openjdk
FROM openjdk:slim
COPY . /targetdir
WORKDIR /targetdir
# Make port 81 available to the world outside this container
EXPOSE 81
CMD ["python", "test.py"]
And the test.py app is in the same directory:
from flask import Flask
import os
app = Flask(__name__)
#app.route("/")
def hello():
html = "<h3>Test:{test}</h3>"
test = os.environ['JAVA_HOME']
return html.format(test = test)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=81)
I'm getting this error:
D:\MyApps\Docker Toolbox\Docker Toolbox\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"python\": executable file not found in $PATH": unknown.
What exactly am I doing wrong here? I'm new to docker, perhaps I'm missing a step.
Additional details
My goal
I have to run a python program that runs a Java file. The python library I'm using requires the path to JAVA_HOME.
My issues:
I do not know Java, so I cannot run the file properly.
My entire code is in Python, except this Java bit
The Python wrapper runs the file in a way I need it to run.
An easier solution to the above issue is to use multi-stage docker containers where you can copy the content from one to another. In the above case you can have openjdk:slim as the base container and then use content from a python container to be copied over into this base container as follows:
FROM openjdk:slim
COPY --from=python:3.6 / /
...
<normal instructions for python container continues>
...
This feature is available as of Docker 17.05 and there are more things you can do using multi-stage build as in copying only the content you need from one to another.
Reference documentation
OK it took me a little while to figure it out. And my thanks go to this answer.
I think my approach didn't work because I did not have a basic version of Linux.
So it goes like this:
Get Linux (I'm using Alpine because it's barebones)
Get Java via the package manager
Get Python, PIP
OPTIONAL: find and set JAVA_HOME
Find the path to JAVA_HOME. Perhaps there is a better way to do this, but I did this running the running the container, then I looked inside the container using docker exec -it [COINTAINER ID] bin/bash and found it.
Set JAVA_HOME in dockerfile and build + run it all again
Here is the final Dockerfile ( it should work with the python code in the question) :
### 1. Get Linux
FROM alpine:3.7
### 2. Get Java via the package manager
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
### 3. Get Python, PIP
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
### Get Flask for the app
RUN pip install --trusted-host pypi.python.org flask
####
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
#ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
####
EXPOSE 81
ADD test.py /
CMD ["python", "test.py"]
I'm new to Docker, so this may not be the best possible solution. I'm open to suggestions.
UPDATE: COMMON ISUUES
Difficulty using python packages
As Joabe Lucena pointed out here, Alpine can have issues certain python packages.
I recommend that you use a Linux distro that works best for you, e.g. centos.
Another alternative is to simply use docker-java-python image from docker hub. https://hub.docker.com/r/rappdw/docker-java-python
FROM rappdw/docker-java-python:openjdk1.8.0_171-python3.6.6
RUN java -version
RUN python --version
I found Sunny Pal's answer very useful but I made the copy more specific and added the necessary environment variables and update-alternatives lines so that Java was accessible from the command line in the Python container.
FROM python:3.9-slim
COPY --from=openjdk:8-jre-slim /usr/local/openjdk-8 /usr/local/openjdk-8
ENV JAVA_HOME /usr/local/openjdk-8
RUN update-alternatives --install /usr/bin/java java /usr/local/openjdk-8/bin/java 1
...
Oh, let me add my five cents. I took python slim as a base image. Then I found open-jdk-11 (Note, open-jdk-10 will fail because it is not supported) base image code!... And copy-pasted it into my docker file.
Note, copy-paste driven development is cool... ONLY when you understand each line you use in your code!!!
And here it is!
<!-- language: shell -->
FROM python:3.7.2-slim
# Do your stuff, install python.
# and now Jdk
RUN rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get update && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ENV JAVA_VERSION jdk-11.0.2+7
COPY slim-java* /usr/local/bin/
RUN set -eux; \
ARCH="$(dpkg --print-architecture)"; \
case "${ARCH}" in \
ppc64el|ppc64le) \
ESUM='c18364a778b1b990e8e62d094377af48b000f9f6a64ec21baff6a032af06386d'; \
BINARY_URL='https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_ppc64le_linux_hotspot_11.0.1_13.tar.gz'; \
;; \
s390x) \
ESUM='e39aacc270731dadcdc000aaaf709adae7a08113ccf5b4a045bc87fc13458d71'; \
BINARY_URL='https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11%2B28/OpenJDK11-jdk_s390x_linux_hotspot_11_28.tar.gz'; \
;; \
amd64|x86_64) \
ESUM='d89304a971e5186e80b6a48a9415e49583b7a5a9315ba5552d373be7782fc528'; \
BINARY_URL='https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.2_7.tar.gz'; \
;; \
aarch64|arm64) \
ESUM='b66121b9a0c2e7176373e670a499b9d55344bcb326f67140ad6d0dc24d13d3e2'; \
BINARY_URL='https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.1%2B13/OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.1_13.tar.gz'; \
;; \
*) \
echo "Unsupported arch: ${ARCH}"; \
exit 1; \
;; \
esac; \
curl -Lso /tmp/openjdk.tar.gz ${BINARY_URL}; \
sha256sum /tmp/openjdk.tar.gz; \
mkdir -p /opt/java/openjdk; \
cd /opt/java/openjdk; \
echo "${ESUM} /tmp/openjdk.tar.gz" | sha256sum -c -; \
tar -xf /tmp/openjdk.tar.gz; \
jdir=$(dirname $(dirname $(find /opt/java/openjdk -name javac))); \
mv ${jdir}/* /opt/java/openjdk; \
export PATH="/opt/java/openjdk/bin:$PATH"; \
apt-get update; apt-get install -y --no-install-recommends binutils; \
/usr/local/bin/slim-java.sh /opt/java/openjdk; \
apt-get remove -y binutils; \
rm -rf /var/lib/apt/lists/*; \
rm -rf ${jdir} /tmp/openjdk.tar.gz;
ENV JAVA_HOME=/opt/java/openjdk \
PATH="/opt/java/openjdk/bin:$PATH"
ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport"
Now references.
https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/11/jdk/ubuntu/Dockerfile.hotspot.releases.slim
https://hub.docker.com/_/python/
https://hub.docker.com/r/adoptopenjdk/openjdk11/
I used them to answer this question, which may help you sometime.
Running Python and Java in Docker
I believe that by adding FROM openjdk:slim line, you tell docker to execute all of your subsequent commands in openjdk container (which does not have python)
I would approach this by creating two separate containers for openjdk and python and specify individual sets of commands for them.
Docker is made to modularize your solutions and mashing everything into one container is usually a bad practice.
I tried pajamas's anwser which worked very well for creating this image. However, when trying to install packages like gensim, pandas or else, I faced some errors like: don't know how to compile Fortran code on platform 'posix'. I searched and tried this, this and that but none worked for me.
So, based on pajamas's anwser I decided to convert his image from Alpine to Centos which worked very well. So here's a Dockerfile that might help someone who's may be struggling in this scenario like I was:
# Get Linux
FROM centos:7
# Install Java
RUN yum update -y \
&& yum install java-1.8.0-openjdk -y \
&& yum clean all \
&& rm -rf /var/cache/yum
# Set JAVA_HOME environment var
ENV JAVA_HOME="/usr/lib/jvm/jre-openjdk"
# Install Python
RUN yum install python3 -y \
&& pip3 install --upgrade pip setuptools wheel \
&& 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 \
&& yum clean all \
&& rm -rf /var/cache/yum
CMD ["bash"]
you should have one FROM in your dockerfile
(unless you use multi-stage build for the docker)
I think i found easiest way to mix java jdk 17 and python3. I is not working on python2
FROM openjdk:17.0.1-jdk-slim
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-get install -y python3-pip
Software Commons have python3 lightweight version. (3.9.1 version)
U can also install some libraries like that.
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install numpy && \
python3 -m pip install opencv-python
OR
RUN apt-get update && \
apt-get install -y ffmpeg
Easiest is to just start from a Python image and add the OpenJDK. Note that FROM openjdk has been deprecated and replaced with eclipse-temurin
FROM python:3.10
ENV JAVA_HOME=/opt/java/openjdk
COPY --from=eclipse-temurin:17-jre $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"
RUN pip install --trusted-host pypi.python.org flask
See How to use this Image - Using a different base Image section of https://hub.docker.com/_/eclipse-temurin for details.
Instead of using FROM openjdk:slim you can separately install Java, please refer below example:
# 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
Are there Docker images for specific Java 9 modules?
I guess there should appear base images for FROM java:9, but how would optional modules come, if my base would be from minimal core Java 9 module.
Here is one example:
FROM java:9
COPY /target/myswarmproject-swarm.jar /home/myswarm-swarm.jar
EXPOSE 8080
CMD java -jar /home/myswarmproject-swarm.jar
Previous dockerfile example is for wildfly swarm project which is deployed as .jar into the container.
Here is my implementation, also found at adenix/java:9u181:
FROM ubuntu:16.04
RUN \
apt update && \
apt install -y curl && \
curl -jkL -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.tar.gz -o jdk-9_linux-x64_bin.tar.gz && \
apt remove -y curl && \
apt clean && \
apt -y autoremove && \
rm -rf /var/lib/apt/lists/* && \
tar xvzf jdk-9_linux-x64_bin.tar.gz -C /opt/ && \
rm -rf jdk-9_linux-x64_bin.tar.gz && \
update-alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 100 && \
update-alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 100 && \
update-alternatives --install /usr/bin/jshell jshell /opt/jdk-9/bin/jshell 100
CMD ["jshell"]
You could implement this by either duplicating this Docker file or using FROM adenix/java:9u181 in your Dockerfile.