ATOM Documentation

← Back to App

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

  1. **Dockerfile** - Modified to build Next.js inside the container:

# Copy source and build

COPY . .

RUN npm run build

```

  1. **.dockerignore** - Simplified to exclude .next/ entirely:

Results

MetricBeforeAfterImprovement
**Image Size**1.1 GB531 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:**

  1. **No .dockerignore negation issues** - All dependencies installed during build
  2. **Standalone artifacts complete** - Next.js creates proper standalone output
  3. **Reproducible builds** - Same environment every time
  4. **No local build step** - Just fly deploy and 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

  1. **Dockerfile** - Changed from local build to in-container build
  2. **.dockerignore** - Simplified to exclude .next/ directory
  3. **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 --tail

Performance 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