我正在尝试为一个名为Tabula的Java库使用Python包装器。我需要我的Docker容器中的Python和Java映像。我使用的是openjdk:8
和python:3.5.3
图像。我正在尝试使用构建该文件,但它返回以下消息:
/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方法?
发布于 2017-06-29 21:29:14
这个Dockerfile无法工作,因为开头的多个FROM
语句并不意味着您认为它意味着什么。这并不意味着您在FROM
语句中引用的图像的所有内容都会以某种方式在您正在构建的映像中结束,它实际上意味着在整个对接过程中有两个不同的概念:
您所描述的行为使我假定您正在使用这样的早期版本。让我解释一下在这个Dockerfile上运行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!"
正如你所看到的,这不是你想要的。
相反,您应该构建一个映像,首先安装运行时(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 ...
请注意,我还没有测试上述代码片段,您可能需要修改一些内容。
https://stackoverflow.com/questions/44833938
复制相似问题