1

I am trying to use a Python wrapper for a Java library called Tabula. I need both Python and Java images within my Docker container. I am using the openjdk:8 and python:3.5.3 images. I am trying to build the file using Docker-compose, but it returns the following message:

/bin/sh: 1: java: not found

when it reaches the line RUN java -version within the Dockerfile. The line RUN find / -name "java" also doesn't return anything, so I can't even find where Java is being installed in the Docker environment.

Here is my Dockerfile:

FROM python:3.5.3
FROM openjdk:8
FROM tailordev/pandas

RUN apt-get update && apt-get install -y \
    python3-pip

# Create code directory
ENV APP_HOME /usr/src/app
RUN mkdir -p $APP_HOME/temp
WORKDIR /$APP_HOME

# Install app dependencies
ADD requirements.txt $APP_HOME
RUN pip3 install -r requirements.txt

# Copy source code
COPY *.py $APP_HOME/

RUN find / -name "java"
RUN java -version

ENTRYPOINT [ "python3", "runner.py" ]

How do I install Java within the Docker container so that the Python wrapper class can invoke Java methods?

1 Answer 1

2

This Dockerfile can not work because the multiple FROM statements at the beginning don't mean what you think it means. It doesn't mean that all the contents of the Images you're referring to in the FROM statements will end up in the Images you're building somehow, it actually meant two different concepts throughout the history of docker:

  • In the newer Versions of Docker multi stage builds, which is a very different thing from what you're trying to achieve (but very interesting nontheless).
  • In earlier Versions of Docker, it gave you the ability to simply build multiple images in one Dockerfile.

The behavior you are describing makes me assume you are using such an earlier Version. Let me explain what's actually happening when you run docker build on this Dockerfile:

FROM python:3.5.3
# Docker: "The User wants me to build an 
  Image that is based on python:3.5.3. No Problem!"
# Docker: "Ah, the next FROM Statement is coming up, 
  which means that the User is done with building this image" 
FROM openjdk:8
# Docker: "The User wants me to build an Image that is based on openjdk:8. No Problem!"
# Docker: "Ah, the next FROM Statement is coming up, 
  which means that the User is done with building this image" 
FROM tailordev/pandas
# Docker: "The User wants me to build an Image that is based on python:3.5.3. No Problem!"

# Docker: "A RUN Statement is coming up. I'll put this as a layer in the Image the user is asking me to build"
RUN apt-get update && apt-get install -y \
    python3-pip

...

# Docker: "EOF Reached, nothing more to do!"

As you can see, this is not what you want.

What you should do instead is build a single image where you will first install your runtimes (python, java, ..), and then your application specific dependencies. The last two parts you're already doing, here's how you could go about installing your general dependencies:

# Let's start from the Alpine Java Image
FROM openjdk:8-jre-alpine

# Install Python runtime
RUN apk add --update \
    python \
    python-dev \
    py-pip \
    build-base \
  && pip install virtualenv \
  && rm -rf /var/cache/apk/*

# Install your framework dependencies
RUN pip install numpy scipy pandas

... do the rest ...

Note that I haven't tested the above snippet, you may have to adapt a few things.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.