1️⃣ What was released / announced
Docker just rolled out a minor but eye‑opening change in the Docker Engine (v24.0.5) that tightens the way the daemon interprets the build context. In plain English: Docker now ignores files that match both .dockerignore and .gitignore when you run docker build. The change was introduced to cut down on accidental inclusion of large source files, but it also surfaces a long‑standing quirk – Docker’s ignore handling has always been a bit weird and undocumented.
2️⃣ Why it matters
If you’re building AI pipelines, model containers, or any data‑intensive service, the size of your image directly impacts:
- Cold‑start latency – larger layers mean longer pulls on the edge.
- CI/CD costs – every extra megabyte adds up in cloud storage and transfer fees.
- Security surface area – stray source files, credentials, or test data can unintentionally ship with your image.
The new behavior forces us to audit our ignore files. Many teams rely on a single .gitignore and assume Docker will respect it – that’s no longer safe. Conversely, developers who already maintain a tight .dockerignore will see smaller, more deterministic images without any extra work.
3️⃣ How to use it – practical steps
Step 1: Audit your ignore files
# List files that Docker will actually send to the daemon
docker build --no-cache --progress=plain - <<'EOF'
FROM alpine:3.18
WORKDIR /app
COPY . .
RUN echo "Build context contains: $(ls -1)"
EOF
EOF
Run the snippet in the root of your repo. The RUN echo will print the files that survived the ignore filters. If you see files you didn’t expect, you probably need to adjust your ignore lists.
Step 2: Consolidate .dockerignore
Create a dedicated .dockerignore that explicitly lists everything you never want in an image. A good baseline for AI workloads looks like this:
# Version control
.git
.gitignore
# Python caches
__pycache__/
*.pyc
# Data & model artifacts (keep them out of the image)
data/**
models/**
*.h5
*.pt
# IDE / editor junk
*.vscode
*.idea
# Large notebooks you don’t need at runtime
*.ipynb_checkpoints/
Step 3: Keep .gitignore for source‑control only
If you previously duplicated entries between .gitignore and .dockerignore, you can now trim the Docker file. The engine will automatically drop anything that appears in both places, but it’s still a best practice to be explicit – it avoids surprises when a teammate adds a new pattern only to .gitignore.
Step 4: Verify image size locally
# Build with BuildKit (enabled by default in recent Docker versions)
DOCKER_BUILDKIT=1 docker build -t my‑ai‑service:latest .
# Inspect the size of each layer
docker image history my‑ai‑service:latest
If you notice a sudden jump in layer size after a change, re‑run the docker build command from Step 1 to see what slipped through.
Step 5: Automate the check in CI
Add a quick sanity test to your CI pipeline (GitHub Actions, GitLab CI, etc.):
name: Docker Context Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run context audit
run: |
docker build --no-cache --progress=plain - <<'EOF'
FROM alpine:3.18
WORKDIR /app
COPY . .
RUN echo "Context files: $(ls -1)"
EOF
If the job prints any file you didn’t intend to ship, the build will fail, forcing a quick fix before merging.
4️⃣ My take – why I’m both excited and cautious
As someone who builds AI infrastructure at scale, I spend a lot of time wrestling with image bloat. A typical model serving container can easily balloon to >1 GB when we accidentally bundle training data, caches, or even the entire node_modules tree from a dev environment. The new Docker ignore handling nudges us toward a cleaner separation of source and runtime.
That said, the change also exposes a hidden dependency: many open‑source projects (including some of the Docker‑based MLOps tools I love) assume a single .gitignore is enough. Suddenly, they start shipping extra files, and you see those mysterious “extra‑large” layers in production. The fix is simple – add a proper .dockerignore – but it’s a reminder that Docker’s documentation still lags behind its own behavior.
In practice, I’ve started a “Docker Hygiene Sprint” for every new microservice we spin up at Griffin AI Tech:
- Draft a minimal
.dockerignore(the template above is my starting point). - Run the context audit locally.
- Gate the image size with a CI step.
- Pin the base image (e.g.,
python:3.11-slim) to keep the attack surface small.
The payoff is immediate: our model‑serving pods now pull 30 % faster on GKE, and we’ve cut down on accidental credential leaks (a stray .env file that used to sneak into the image is now caught by the audit).
Bottom line: Docker isn’t mysterious anymore – it’s just more explicit about what it includes. Embrace the explicitness, tighten your ignore files, and you’ll get leaner, safer containers that play nicely with the AI workloads you’re shipping to the cloud.
If you found this useful, feel free to drop a comment or share your own Docker quirks. I’m always up for swapping stories about the weird things that happen when you try to containerize massive models.
Top comments (0)