Docker-compose找不到Java

我正在尝试使用名为Tabula的Java库的Python包装器。 我需要在我的Docker容器中的Python和Java图像。 我正在使用openjdk:8python:3.5.3图像。 我正在尝试使用Docker-compose构build文件,但它返回以下消息:

 /bin/sh: 1: java: not found 

当它到达Dockerfile中的RUN java -version行时。 RUN find / -name "java"这一行也不会返回任何东西,所以我甚至找不到在Docker环境中安装Java的地方。

这是我的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" ] 

如何在Docker容器中安装Java,以便Python包装类可以调用Java方法?

这个Dockerfile不能工作,因为在开始的多个FROM语句并不意味着你的想法。 这并不意味着在FROM语句中引用的所有图像的内容都将以您所创build的图像为结尾,实际上这意味着在整个Docker历史中有两个不同的概念:

  • 在较新版本的Docker 多阶段构build中 ,这与您尝试实现的非常不同(但是非常有趣)。
  • 在较早版本的Docker中,它使您能够在一个Dockerfile中简单构build多个图像。

你所描述的行为使我假设你正在使用这样一个较早的版本。 让我解释一下当你在Dockerfile上运行docker docker build时实际发生的事情:

 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!" 

正如你所看到的,这不是你想要的。

你应该做的是build立一个单一的图像,你将首先安装你的运行时(python,java,..),然后是你的应用程序特定的依赖关系。 最后两部分你已经在做,下面是如何安装你的一般依赖:

 # 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 ... 

请注意,我没有testing过上面的代码片段,你可能需要适应一些东西。