Skip to content
Back to skills

Dockerfile Generator

BSecurity

Generate optimized Dockerfiles with multi-stage builds and best practices. Use when containerizing applications or creating Docker configurations.

  • 666 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added February 8, 2026
developmentpythongojavasqlreactnodenodejsexpressfastapidocker

Works with

  • api

Security analysis

B76/100
  • criticalAccesses sensitive system or user directories
  • highPerforms destructive filesystem operations
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill dockerfile-generator --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dockerfile Generator?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dockerfile Generator
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-dockerfile-generator/badge)](https://www.skillsdirectory.com/skills/majiayu000-dockerfile-generator)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: dockerfile-generator
description: Generate optimized Dockerfiles with multi-stage builds and best practices. Use when containerizing applications or creating Docker configurations.
---

# Dockerfile Generator Skill

最適化されたDockerfileを生成するスキルです。

## 概要

プロジェクトの種類に応じた、セキュアで効率的なDockerfileを自動生成します。

## 主な機能

- **マルチステージビルド**: イメージサイズ削減
- **セキュリティ**: 非rootユーザー、最小権限
- **キャッシュ最適化**: ビルド時間短縮
- **ベストプラクティス**: Docker推奨設定
- **複数言語対応**: Node.js、Python、Go、Java等

## 生成例

### Node.js (Express)

```dockerfile
# マルチステージビルド
FROM node:18-alpine AS builder

WORKDIR /app

# 依存関係のみ先にコピー(キャッシュ最適化)
COPY package*.json ./
RUN npm ci --only=production

# ソースコードコピー
COPY . .

# 本番イメージ
FROM node:18-alpine

# 非rootユーザー作成
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001

WORKDIR /app

# ビルド成果物をコピー
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --chown=nodejs:nodejs . .

USER nodejs

EXPOSE 3000

CMD ["node", "server.js"]
```

### Python (FastAPI)

```dockerfile
FROM python:3.11-slim AS builder

WORKDIR /app

# システム依存関係
RUN apt-get update && \
    apt-get install -y --no-install-recommends gcc && \
    rm -rf /var/lib/apt/lists/*

# Python依存関係
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt

# 本番イメージ
FROM python:3.11-slim

RUN adduser --disabled-password --gecos '' appuser

WORKDIR /app

# ビルドしたパッケージをコピー
COPY --from=builder /root/.local /home/appuser/.local
COPY --chown=appuser:appuser . .

USER appuser

ENV PATH=/home/appuser/.local/bin:$PATH

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
```

### Go

```dockerfile
# ビルドステージ
FROM golang:1.21-alpine AS builder

WORKDIR /app

# 依存関係
COPY go.mod go.sum ./
RUN go mod download

# ビルド
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

# 最小イメージ
FROM scratch

COPY --from=builder /app/main /main

EXPOSE 8080

ENTRYPOINT ["/main"]
```

### React (静的サイト)

```dockerfile
# ビルドステージ
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

# Nginxで配信
FROM nginx:alpine

COPY --from=builder /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
```

## .dockerignore

```
node_modules
npm-debug.log
.git
.gitignore
README.md
.env
.DS_Store
*.log
dist
build
coverage
```

## docker-compose.yml

```yaml
version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
    volumes:
      - ./data:/app/data
    restart: unless-stopped

  database:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  postgres_data:
```

## ベストプラクティス

1. **マルチステージビルド**: イメージサイズ削減
2. **レイヤーキャッシュ**: 変更の少ないファイルから順に
3. **非rootユーザー**: セキュリティ向上
4. **.dockerignore**: 不要ファイル除外
5. **ヘルスチェック**: コンテナ監視

## バージョン情報

- スキルバージョン: 1.0.0

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.