Prompt
Manage environment variables in Docker configurations with appropriate scope, placement, and documentation:
- Set environment variables with appropriate scope:
- Use variables only where needed, not globally
- Set temporary variables like
DEBIAN_FRONTENDonly within the commands that need them: ```dockerfileDo this:
RUN apt-get update
&& DEBIAN_FRONTEND=noninteractive apt-get install -y –no-install-recommends
package1 package2
Not this:
ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y package1 package2 ```
- Place variables logically:
- Group related variables under descriptive comments
- Place variables near their related commands
- Use ARG instead of ENV for build-time values, especially versions:
# version details ARG LIBFABRIC_VERSION="1.20.0" ARG PYTORCH_VERSION="2.2.2"
- Document variables properly:
- Add comments explaining non-obvious configurations
- Include links to relevant documentation when appropriate
- Document compatibility requirements:
# Gaudi does not currently support Python 3.11, so we downgrade to 3.10 # https://docs.habana.ai/en/latest/Support_Matrix/Support_Matrix.html
- Clean up unnecessary variables:
- Remove obsolete or unused environment variables
- Consider using dedicated configuration files under /etc/ instead of environment variables when appropriate