Docker-compose cannot find Java

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.

  • How to check if docker daemon is running?
  • docker container interface not being attached to docker0 bridge in coreos
  • Can't delete pods in pending state?
  • Dockerized Spring Cloud Stream services with Kafka broker unable to connect to Zookeeper
  • Where could I find docker-standard environment variables like DOCKER_HOST?
  • .NET Core 1.1, Docker Build encounters Couldn't find 'project.json' with csproj
  • 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?

  • How to load docker image from tar file
  • 'nutc': unknown terminal type. docker
  • Docker: Can't pick up config file for nginx on Windows 10
  • chef-container + chef-vault
  • “Could not find a version that satisfies the requirement cv2==1.0” when deploy Docker app with Anaconda and OpenCV to Heroku
  • Connecting to localhost mysql server from inside docker container on macOS
  • One Solution collect form web for “Docker-compose cannot find Java”

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.