Good Code
The good version uses an absolute WORKDIR, copies known files, and keeps installation inputs visible.
Lesson 05
Use WORKDIR and COPY intentionally so filesystem paths are clear and remote side effects are not hidden in ADD.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY app ./app
CMD ["python", "-m", "app"]FROM python:latest
RUN mkdir app
RUN cd app && pip install flask
ADD https://example.com/app.tar.gz /app
COPY . /The good version uses an absolute WORKDIR, copies known files, and keeps installation inputs visible.
The bad version relies on cd inside individual layers, fetches remote content through ADD, and copies the repository into the image root.