Optimized Docker deployments for Google Antigravity projects including multi-stage builds and production images.
# Docker Deployment Patterns for Google Antigravity
Create optimized Docker deployments in your Google Antigravity IDE projects. This comprehensive guide covers multi-stage builds, optimization, and production configurations optimized for Gemini 3 agentic development.
## Multi-Stage Dockerfile
Create an optimized Next.js Dockerfile:
```dockerfile
# Dockerfile
# Stage 1: Dependencies
FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --only=production
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Stage 3: Runner
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy built assets
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set permissions
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
ENV PORT=3000
CMD ["node", "server.js"]
```
## Docker Compose
Configure for development and production:
```yaml
# docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
target: runner
ports:
- "3000:3000"
environment:
- DATABASE_URL=${DATABASE_URL}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
depends_on:
- db
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
db:
image: postgres:16-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
ports:
- "5432:5432"
volumes:
postgres_data:
```
## Development Dockerfile
Configure for local development:
```dockerfile
# Dockerfile.dev
FROM node:20-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "run", "dev"]
```
```yaml
# docker-compose.dev.yml
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- .:/app
- /app/node_modules
ports:
- "3000:3000"
environment:
- NODE_ENV=development
depends_on:
- db
db:
image: postgres:16-alpine
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=antigravity
ports:
- "5432:5432"
```
## Build Scripts
Create automation scripts:
```bash
#!/bin/bash
# scripts/docker-build.sh
set -e
IMAGE_NAME="antigravity-ai"
REGISTRY="your-registry.com"
TAG=${1:-latest}
echo "Building Docker image..."
docker build
--cache-from ${REGISTRY}/${IMAGE_NAME}:latest
-t ${IMAGE_NAME}:${TAG}
-t ${REGISTRY}/${IMAGE_NAME}:${TAG}
.
echo "Build complete: ${IMAGE_NAME}:${TAG}"
if [ "$2" == "--push" ]; then
echo "Pushing to registry..."
docker push ${REGISTRY}/${IMAGE_NAME}:${TAG}
echo "Push complete"
fi
```
## CI/CD Pipeline
Configure GitHub Actions:
```yaml
# .github/workflows/docker.yml
name: Docker Build
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
```
## Best Practices
1. **Use multi-stage builds** for smaller images
2. **Create non-root users** for security
3. **Leverage build cache** for faster builds
4. **Use .dockerignore** to exclude files
5. **Pin base image versions** for reproducibility
6. **Add health checks** for monitoring
7. **Use Docker Compose** for developmentThis docker prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their docker implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For docker projects, consider mentioning your framework version, coding style, and any specific libraries you're using.