Skip to content

Optimize Docker build with layer caching and .dockerignore#83

Merged
danielcuthbert merged 3 commits intomasterfrom
copilot/optimize-docker-build-process
Nov 25, 2025
Merged

Optimize Docker build with layer caching and .dockerignore#83
danielcuthbert merged 3 commits intomasterfrom
copilot/optimize-docker-build-process

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Docker builds were slow due to poor layer caching (copying all code before deps), running migrations at build time, and no .dockerignore.

Changes

  • Added .dockerignore — excludes .git/, screenshots/, terraform/, docs, and build artifacts (~1MB+ reduction in build context)

  • Optimized Dockerfile:

    • Switch from alpine:latest to python:3.11-slim (specific version, smaller image)
    • Copy requirements.txt first, install deps, then copy code (enables dependency layer caching)
    • Move migrate to container startup via CMD (was baked into build)
    • Remove duplicate psycopg2 install (already in requirements.txt) and unused Pillow
    • Consolidate RUN commands and clean apt cache in same layer
# Before: deps reinstalled on every code change
COPY . /app
RUN pip install -r requirements.txt

# After: deps cached when only code changes
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
Original prompt

This section details on the original issue you should resolve

<issue_title>Painful Build</issue_title>
<issue_description>We are aware that the docker build process is ugly and slow and now looking at how to make this leaner and faster for all.

Screenshot 2022-03-17 at 17 04 31

</issue_description>

<agent_instructions>Try and optimise the docker build process so it isn't painful and slow </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 25, 2025 13:10
…ckerignore

Co-authored-by: danielcuthbert <7882621+danielcuthbert@users.noreply.github.com>
…uction note for migrations

Co-authored-by: danielcuthbert <7882621+danielcuthbert@users.noreply.github.com>
@danielcuthbert danielcuthbert marked this pull request as ready for review November 25, 2025 13:12
@danielcuthbert danielcuthbert merged commit f8f2794 into master Nov 25, 2025
6 checks passed
Copilot AI changed the title [WIP] Optimize the docker build process for speed and efficiency Optimize Docker build with layer caching and .dockerignore Nov 25, 2025
@danielcuthbert danielcuthbert deleted the copilot/optimize-docker-build-process branch November 25, 2025 13:12
Copilot AI requested a review from danielcuthbert November 25, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Painful Build

2 participants