Q: 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. As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.
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. But during API execution it is not recognized by Python.
The "app.yaml" file used:
runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app

Below are the the Docker file used in Deploy:
### 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
Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?
Are there any additional settings missing?

A: You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.
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.
