An environment variable is a named value supplied through a process environment to configure an application without embedding the setting in application code. Production workflows use it across image construction, Kubernetes deployment, and continuous integration. section 3.2.2 section 3.3.5
Use environment variables at different operational boundaries:
- Set image-level values with Dockerfile ENV; combine it with a build-time ARG when selecting values such as ENVIRONMENT. section 3.2.2
- Store non-sensitive settings such as database URLs and API endpoints in Kubernetes ConfigMaps, then inject selected keys into container environments. section 3.3.5
- Keep credentials in Kubernetes Secrets or GitLab CI/CD variables rather than ordinary configuration, while recognizing that base64 encoding is not encryption. section 3.3.5 section 3.4.1
Injecting deployment configuration
A Kubernetes Pod can map DATABASE_URL from the database-url key in test-configmap. The application reads the resulting process variable while the ConfigMap remains separate from its container image and code. section 3.3.5
Listing 3.2 An example Dockerfile for Python applications
FROM python:3.10-slim-buster #1
WORKDIR /app #2
RUN apt-get update && \
apt-get install --no-install-recommends -y \
build-essential \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
COPY requirements.txt /app/requirements.txt #3
RUN pip3 install --upgrade pip #3
RUN pip3 install --no-cache-dir -r requirements.txt #3
COPY . /app #4
EXPOSE 8083
ENV PYTHONPATH="/app" #5
ARG environment #5
ENV ENVIRONMENT $environment #5
RUN chmod +x /app/entrypoint.sh #6
ENTRYPOINT ["/app/entrypoint.sh"] #6
Inspect the Dockerfile pattern that declares PYTHONPATH, accepts an environment build argument, and exposes ENVIRONMENT to the container. section 3.2.2


















