How does Dockerfile refer to the environment variable of the host?

  docker, question

When I set the environment variable of the mirror image, its value comes from the environment variable of the host computer.

Dockerfile cannot directly use the environment variables of the host when building the image, but it can be implemented in the following ways

Dockerfile:

...
 ARG JAVA_HOME
 ENV JAVA_HOME $JAVA_HOME
 ...

Build for use:

docker build --build-arg JAVA_HOME=$JAVA_HOME   ...