繁体   English   中英

Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process)

[英]Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process)

我在 Google App Engine 上部署了一个 Python 项目。 由于项目依赖于 Java,我使用了一个 Docker 容器,配置了两个环境:Python + Z2218178780E5A9

However, when I make a call to my Python service in GAE it's getting " java command is not found from this Python process. Please ensure Java is installed and PATH is set for java " error .

在 Docker 文件的构建过程中,我可以在安装后访问 Java。 但是在 API 执行期间,它无法被 Python 识别。

使用的“app.yaml”文件:

runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app

下面是 Deploy 中使用的 Docker 文件:

### 1. Get Linux
FROM alpine:3.7
    
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

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

#### 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"
RUN export JAVA_HOME
ENV PATH $PATH:$JAVA_HOME/bin
RUN export PATH
RUN find / -name "java"
RUN java -version  

FROM python:3.7
EXPOSE 8080

ENV APP_HOME /src
WORKDIR /src

COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt

COPY . /src
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]

这是部署过程中 RUN java RUN java -version命令的打印输出: RUN java -version 命令

有谁知道为什么即使 Python 和 Java 在 App Engine 上的同一服务上运行也会发生错误? 是否缺少任何其他设置?

您在 Dockerfile 中使用了两个FROM ,因此您实际上是在执行多阶段Docker 构建,但您做错了。 多阶段构建应该是这样的:

### 1. Get Linux
FROM alpine:3.7 as build
# here you install with apk and build your Java program

FROM python:3.7
EXPOSE 8080 
...
# here you copy what you need from the previous Docker build, though 
# since it was Java, which is not installed here anymore because it is
# a python image, you need to consider if you really need a multi-stage 
# build 
COPY --from=builder /src /src

否则,只需删除第二个FROM python:3.7并使用 apk 安装它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM