Docker Image Size Fix - SUCCESS! š
Problem Solved
**Issue:** Docker image grew to 1.1 GB and Next.js was failing to start with "Cannot find module" errors.
**Root Cause:** .dockerignore negation patterns don't work reliably with Docker COPY for nested directories.
Solution Implemented: **Option 2 - Build In-Container** ā
Changes Made
- **Dockerfile** - Modified to build Next.js inside the container:
# Copy source and build
COPY . .
RUN npm run build
```
- **
.dockerignore** - Simplified to exclude.next/entirely:
Results
| Metric | Before | After | Improvement |
|---|---|---|---|
| **Image Size** | 1.1 GB | 531 MB | **52% reduction** (-569 MB) |
| **Next.js** | ā Crashing | ā Running | **Fixed** |
| **Health Checks** | ā Failing | ā Passing | **Fixed** |
| **HTTP Response** | ā Timeout | ā 200 OK | **Fixed** |
Verification
# Health checks passing
$ fly status -a atom-saas
CHECKS: 1 total, 1 passing ā
# App responding
$ curl -s -o /dev/null -w "%{http_code}" https://atom-saas.fly.dev/
200 ā
# Image size
Image: 531 MB ā
Why This Works
**In-Container Build Benefits:**
- **No
.dockerignorenegation issues** - All dependencies installed during build - **Standalone artifacts complete** - Next.js creates proper standalone output
- **Reproducible builds** - Same environment every time
- **No local build step** - Just
fly deployand it works
**Trade-offs:**
- Build context larger (1.35 GB) - takes ~2 minutes to upload
- Build time longer (~5-7 minutes total) - compiles TypeScript, runs webpack
- Image size 531 MB (acceptable for the functionality)
Files Modified
- **
Dockerfile** - Changed from local build to in-container build - **
.dockerignore** - Simplified to exclude.next/directory - **No other changes needed** - Works with existing infrastructure
Deployment Commands
# Deploy (everything automated)
fly deploy -a atom-saas --remote-only
# Check status
fly status -a atom-saas
# View logs
fly logs -a atom-saas --tailPerformance Metrics
**Build Time:** ~5-7 minutes
- Context upload: ~2 minutes (1.35 GB)
- npm install: ~1.5 minutes (2954 packages)
- Next.js build: ~2 minutes
- Python pip install: ~1 minute
- Image push: ~1 minute (531 MB)
**Startup Time:** ~30 seconds
- supervisord starts both processes
- Next.js initializes
- Python FastAPI initializes
- Health checks pass
Conclusion
ā **Image size reduced 52%** (1.1 GB ā 531 MB)
ā **Next.js running successfully**
ā **Health checks passing**
ā **App fully functional**
**Option 2 (In-Container Build) was the right choice!**
---
**Date:** April 9, 2026
**Deployed to:** https://atom-saas.fly.dev
**Image:** registry.fly.io/atom-saas:deployment-01KNTCNXQ1MNCADCWZKNCXPZBS