简体   繁体   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)

I deployed a Python project on Google App Engine.我在 Google App Engine 上部署了一个 Python 项目。 As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.由于项目依赖于 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 . 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 .

During the build process of the Docker file I am able to access Java after installing it.在 Docker 文件的构建过程中,我可以在安装后访问 Java。 But during API execution it is not recognized by Python.但是在 API 执行期间,它无法被 Python 识别。

The "app.yaml" file used:使用的“app.yaml”文件:

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

Below are the the Docker file used in Deploy:下面是 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"]

Here is a printout of the RUN java -version command during the deploy process: RUN java -version command这是部署过程中 RUN java RUN java -version命令的打印输出: RUN java -version 命令

Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?有谁知道为什么即使 Python 和 Java 在 App Engine 上的同一服务上运行也会发生错误? Are there any additional settings missing?是否缺少任何其他设置?

You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.您在 Dockerfile 中使用了两个FROM ,因此您实际上是在执行多阶段Docker 构建,但您做错了。 A multi-stage build should be something like this:多阶段构建应该是这样的:

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

Otherwise, just remove the second FROM python:3.7 and install it with apk.否则,只需删除第二个FROM python:3.7并使用 apk 安装它。

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

相关问题 在这个 Python 进程中找不到 `java` 命令。 请确保已安装 Java 并为 `java` 设置了 PATH - `java` command is not found from this Python process. Please ensure Java is installed and PATH is set for `java` 从命令行Java应用程序上传到Google App Engine中的BlobStore - Uploading to BlobStore in Google App Engine from a Command Line Java Application 无法从 Java 进程构建器和 Linux 运行“python -c ".." '命令 - Cannot run 'python -c ".." ' command from Java Process builder and Linux 从Java运行python脚本时找不到mvn命令 - mvn command not found when running python script from Java 使用 Python 运行时在 Google App Engine 中安装 Java - Installing Java in Google App Engine with Python runtime 在java google app引擎应用程序上执行python - Execute python on a java google app engine application 在Google App Engine上选择Java vs Python - Choosing Java vs Python on Google App Engine Google Cloud Memorystore通过“ App Engine Java标准环境”进行连接 - Google Cloud Memorystore connect from “App Engine Java Standard Environment” 内部命令中的Python和Java - Python and Java in internal command Google App Engine Java中的特定于环境的变量 - Environment Specific Variables In Google App Engine Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM