This will set the value of MY_VAR to “Goodbye” when the image is built.
It is also a good idea to use default values for environment variables in your Dockerfile. This way, if the variable is not set when the image is built, it will use the default value. You can do this by using the ARG directive in your Dockerfile and then using the := operator to set the default value:
# Set a default value for the environment variable
ARG MY_VAR:=Hello World
# Use the environment variable in a command
RUN echo $MY_VAR > /app/output.txt
CMD ["cat", "/app/output.txt"]
In this example, if the value of MY_VAR is not set when the image is built, it will default to the value “Hello World”.