Containers have become the standard for deploying applications. But setting up containerized development environments remains tedious. AI tools can generate Dockerfiles, compose configurations, and Kubernetes manifests—letting you focus on your application, not infrastructure.
AI-Generated Container Configurations#
From Application to Dockerfile#
Describe your app, get a production-ready Dockerfile:
1Prompt:
2Generate a Dockerfile for a Next.js 14 application with:
3- Multi-stage build for small image size
4- Production dependencies only
5- Non-root user for security
6- Health check endpoint
7- Environment variable supportAI Output:
1# Stage 1: Dependencies
2FROM node:20-alpine AS deps
3WORKDIR /app
4
5# Install dependencies based on lockfile
6COPY package.json package-lock.json ./
7RUN npm ci --only=production
8
9# Stage 2: Builder
10FROM node:20-alpine AS builder
11WORKDIR /app
12
13COPY /app/node_modules ./node_modules
14COPY . .
15
16# Build arguments for environment
17ARG NEXT_PUBLIC_API_URL
18ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
19
20# Disable telemetry during build
21ENV NEXT_TELEMETRY_DISABLED=1
22
23RUN npm run build
24
25# Stage 3: Runner
26FROM node:20-alpine AS runner
27WORKDIR /app
28
29ENV NODE_ENV=production
30ENV NEXT_TELEMETRY_DISABLED=1
31
32# Create non-root user
33RUN addgroup --system --gid 1001 nodejs
34RUN adduser --system --uid 1001 nextjs
35
36# Copy built application
37COPY /app/public ./public
38COPY /app/.next/standalone ./
39COPY /app/.next/static ./.next/static
40
41# Set correct permissions
42RUN chown -R nextjs:nodejs /app
43USER nextjs
44
45EXPOSE 3000
46ENV PORT=3000
47ENV HOSTNAME="0.0.0.0"
48
49# Health check
50HEALTHCHECK \
51 CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
52
53CMD ["node", "server.js"]Docker Compose for Development#
AI generates compose files for complex setups:
1# docker-compose.yml (AI-generated)
2version: '3.8'
3
4services:
5 app:
6 build:
7 context: .
8 dockerfile: Dockerfile.dev
9 ports:
10 - "3000:3000"
11 volumes:
12 - .:/app
13 - /app/node_modules # Named volume for dependencies
14 environment:
15 - DATABASE_URL=postgresql://postgres:postgres@db:5432/app_dev
16 - REDIS_URL=redis://redis:6379
17 - NODE_ENV=development
18 depends_on:
19 db:
20 condition: service_healthy
21 redis:
22 condition: service_started
23 command: npm run dev
24
25 db:
26 image: postgres:15-alpine
27 ports:
28 - "5432:5432"
29 environment:
30 POSTGRES_USER: postgres
31 POSTGRES_PASSWORD: postgres
32 POSTGRES_DB: app_dev
33 volumes:
34 - postgres_data:/var/lib/postgresql/data
35 - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init.sql
36 healthcheck:
37 test: ["CMD-SHELL", "pg_isready -U postgres"]
38 interval: 5s
39 timeout: 5s
40 retries: 5
41
42 redis:
43 image: redis:7-alpine
44 ports:
45 - "6379:6379"
46 volumes:
47 - redis_data:/data
48
49 mailhog:
50 image: mailhog/mailhog
51 ports:
52 - "1025:1025" # SMTP
53 - "8025:8025" # Web UI
54
55volumes:
56 postgres_data:
57 redis_data:Kubernetes Manifest Generation#
From Docker Compose to K8s#
AI converts compose files to Kubernetes manifests:
1# deployment.yaml (AI-generated from compose)
2apiVersion: apps/v1
3kind: Deployment
4metadata:
5 name: app
6 labels:
7 app: myapp
8spec:
9 replicas: 3
10 selector:
11 matchLabels:
12 app: myapp
13 template:
14 metadata:
15 labels:
16 app: myapp
17 spec:
18 securityContext:
19 runAsNonRoot: true
20 runAsUser: 1001
21 fsGroup: 1001
22 containers:
23 - name: app
24 image: myapp:latest
25 ports:
26 - containerPort: 3000
27 env:
28 - name: DATABASE_URL
29 valueFrom:
30 secretKeyRef:
31 name: app-secrets
32 key: database-url
33 - name: REDIS_URL
34 valueFrom:
35 configMapKeyRef:
36 name: app-config
37 key: redis-url
38 resources:
39 requests:
40 memory: "256Mi"
41 cpu: "200m"
42 limits:
43 memory: "512Mi"
44 cpu: "500m"
45 livenessProbe:
46 httpGet:
47 path: /api/health
48 port: 3000
49 initialDelaySeconds: 10
50 periodSeconds: 10
51 readinessProbe:
52 httpGet:
53 path: /api/ready
54 port: 3000
55 initialDelaySeconds: 5
56 periodSeconds: 5
57---
58apiVersion: v1
59kind: Service
60metadata:
61 name: app
62spec:
63 selector:
64 app: myapp
65 ports:
66 - port: 80
67 targetPort: 3000
68 type: ClusterIP
69---
70apiVersion: networking.k8s.io/v1
71kind: Ingress
72metadata:
73 name: app
74 annotations:
75 kubernetes.io/ingress.class: nginx
76 cert-manager.io/cluster-issuer: letsencrypt-prod
77spec:
78 tls:
79 - hosts:
80 - app.example.com
81 secretName: app-tls
82 rules:
83 - host: app.example.com
84 http:
85 paths:
86 - path: /
87 pathType: Prefix
88 backend:
89 service:
90 name: app
91 port:
92 number: 80HorizontalPodAutoscaler#
AI generates scaling configurations:
1# AI-generated HPA based on application characteristics
2apiVersion: autoscaling/v2
3kind: HorizontalPodAutoscaler
4metadata:
5 name: app-hpa
6spec:
7 scaleTargetRef:
8 apiVersion: apps/v1
9 kind: Deployment
10 name: app
11 minReplicas: 3
12 maxReplicas: 20
13 metrics:
14 - type: Resource
15 resource:
16 name: cpu
17 target:
18 type: Utilization
19 averageUtilization: 70
20 - type: Resource
21 resource:
22 name: memory
23 target:
24 type: Utilization
25 averageUtilization: 80
26 behavior:
27 scaleDown:
28 stabilizationWindowSeconds: 300 # Wait 5 min before scaling down
29 policies:
30 - type: Percent
31 value: 10
32 periodSeconds: 60
33 scaleUp:
34 stabilizationWindowSeconds: 0 # Scale up immediately
35 policies:
36 - type: Percent
37 value: 100
38 periodSeconds: 15
39 - type: Pods
40 value: 4
41 periodSeconds: 15
42 selectPolicy: MaxAI-Assisted Debugging#
Container Issues#
AI analyzes container logs and suggests fixes:
1# AI analyzes failing container
2$ bootspring container diagnose myapp-pod-xyz
3
4Analysis Results:
5
6Issue: Container repeatedly crashing (CrashLoopBackOff)
7
8Log Analysis:Error: connect ECONNREFUSED 10.0.0.5:5432 at TCPConnectWrap.afterConnect
Root Cause: Database connection refused
Possible causes (ranked by likelihood):
1. Database service not ready before app starts (90%)
2. Database credentials incorrect (5%)
3. Network policy blocking connection (5%)
Recommended Fixes:
1. Add init container to wait for database:
```yaml
initContainers:
- name: wait-for-db
image: busybox
command: ['sh', '-c', 'until nc -z db 5432; do sleep 2; done']
- Add proper dependency in readiness probe:
1readinessProbe:
2 exec:
3 command:
4 - /bin/sh
5 - -c
6 - pg_isready -h db -p 5432
### Resource Analysis
AI optimizes resource requests and limits:
```typescript
const resourceAnalysis = {
deployment: 'app',
period: '7 days',
recommendations: {
cpu: {
current: { request: '200m', limit: '500m' },
actual: { p50: '85m', p95: '180m', p99: '220m' },
recommended: { request: '100m', limit: '300m' },
savings: '50% CPU quota reduction'
},
memory: {
current: { request: '256Mi', limit: '512Mi' },
actual: { p50: '180Mi', p95: '320Mi', p99: '410Mi' },
recommended: { request: '200Mi', limit: '450Mi' },
note: 'Memory spikes near limit - consider increasing'
}
},
alerts: [
'Memory approaching limit during peak hours',
'CPU consistently under-utilized'
]
};
Development Environment Setup#
AI-Generated Dev Containers#
1// .devcontainer/devcontainer.json (AI-generated)
2{
3 "name": "Full Stack Development",
4 "dockerComposeFile": "docker-compose.yml",
5 "service": "app",
6 "workspaceFolder": "/workspace",
7
8 "customizations": {
9 "vscode": {
10 "extensions": [
11 "dbaeumer.vscode-eslint",
12 "esbenp.prettier-vscode",
13 "prisma.prisma",
14 "bradlc.vscode-tailwindcss"
15 ],
16 "settings": {
17 "editor.formatOnSave": true,
18 "editor.defaultFormatter": "esbenp.prettier-vscode"
19 }
20 }
21 },
22
23 "forwardPorts": [3000, 5432, 6379],
24
25 "postCreateCommand": "npm install && npx prisma generate",
26
27 "features": {
28 "ghcr.io/devcontainers/features/node:1": {
29 "version": "20"
30 },
31 "ghcr.io/devcontainers/features/github-cli:1": {}
32 },
33
34 "remoteUser": "node"
35}Multi-Service Development#
AI configures complex local setups:
1# AI-generated for microservices development
2version: '3.8'
3
4services:
5 # API Gateway
6 gateway:
7 build: ./gateway
8 ports:
9 - "8080:8080"
10 environment:
11 - USER_SERVICE_URL=http://user-service:3001
12 - ORDER_SERVICE_URL=http://order-service:3002
13 - PRODUCT_SERVICE_URL=http://product-service:3003
14 depends_on:
15 - user-service
16 - order-service
17 - product-service
18
19 # User Service
20 user-service:
21 build: ./services/user
22 ports:
23 - "3001:3001"
24 environment:
25 - DATABASE_URL=postgresql://postgres:postgres@user-db:5432/users
26 depends_on:
27 - user-db
28
29 user-db:
30 image: postgres:15-alpine
31 environment:
32 POSTGRES_DB: users
33 POSTGRES_PASSWORD: postgres
34
35 # Order Service
36 order-service:
37 build: ./services/order
38 ports:
39 - "3002:3002"
40 environment:
41 - DATABASE_URL=postgresql://postgres:postgres@order-db:5432/orders
42 - KAFKA_BROKERS=kafka:9092
43 depends_on:
44 - order-db
45 - kafka
46
47 order-db:
48 image: postgres:15-alpine
49 environment:
50 POSTGRES_DB: orders
51 POSTGRES_PASSWORD: postgres
52
53 # Product Service
54 product-service:
55 build: ./services/product
56 ports:
57 - "3003:3003"
58 environment:
59 - DATABASE_URL=postgresql://postgres:postgres@product-db:5432/products
60 - ELASTICSEARCH_URL=http://elasticsearch:9200
61 depends_on:
62 - product-db
63 - elasticsearch
64
65 product-db:
66 image: postgres:15-alpine
67 environment:
68 POSTGRES_DB: products
69 POSTGRES_PASSWORD: postgres
70
71 # Infrastructure
72 kafka:
73 image: confluentinc/cp-kafka:7.5.0
74 environment:
75 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
76 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
77 depends_on:
78 - zookeeper
79
80 zookeeper:
81 image: confluentinc/cp-zookeeper:7.5.0
82 environment:
83 ZOOKEEPER_CLIENT_PORT: 2181
84
85 elasticsearch:
86 image: elasticsearch:8.11.0
87 environment:
88 - discovery.type=single-node
89 - xpack.security.enabled=false
90 ports:
91 - "9200:9200"Security Scanning#
AI-Enhanced Container Security#
$ bootspring container security-scan myapp:latestSecurity Scan Results:
| Category | Details |
|---|---|
| Image | myapp:latest |
| Base | node:20-alpine |
| Size | 145MB |
Vulnerabilities:
| Severity | Count | Notes |
|---|---|---|
| Critical | 0 | Pass |
| High | 1 | CVE-2024-1234 in libcurl (fix: upgrade to alpine 3.19.1) |
| Medium | 3 | - |
| Low | 12 | - |
Configuration Issues:
- Running as root: No (Pass)
- Read-only filesystem: No (Recommended)
- Capabilities dropped: Partial (Recommend: Drop all, add only NET_BIND_SERVICE)
- Secrets in image: None detected (Pass)
Recommendations:
-
Update base image:
FROM node:20-alpine3.19 -
Add security context:
securityContext:
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
add: ["NET_BIND_SERVICE"]- Use distroless for production:
FROM gcr.io/distroless/nodejs20-debian12
Best Practices Summary#
AI helps enforce container best practices:
1## Container Best Practices Checklist
2
3### Build
4- [ ] Multi-stage builds for smaller images
5- [ ] Specific version tags (not :latest)
6- [ ] .dockerignore excludes unnecessary files
7- [ ] Layer caching optimized
8
9### Security
10- [ ] Non-root user
11- [ ] Read-only root filesystem
12- [ ] No secrets in image
13- [ ] Minimal base image
14- [ ] Regular security scans
15
16### Runtime
17- [ ] Resource limits set
18- [ ] Health checks configured
19- [ ] Graceful shutdown handling
20- [ ] Logging to stdout/stderr
21
22### Kubernetes
23- [ ] Pod disruption budgets
24- [ ] Horizontal pod autoscaler
25- [ ] Network policies
26- [ ] Service accounts with minimal permissionsConclusion#
Containerization doesn't have to be complex. AI tools can:
- Generate Dockerfiles from application requirements
- Convert compose files to Kubernetes manifests
- Diagnose container issues from logs
- Optimize resource allocation
- Secure images with automated scanning
Focus on your application. Let AI handle the infrastructure.
Bootspring generates production-ready container configurations tailored to your application. From Dockerfile to Kubernetes in minutes.