docker-debugger について
docker-debuggerは、Dockerのビルド、実行、ネットワーク、パフォーマンスの問題を調べるスキルです。開発者向けに、診断情報の収集、ログ分析、対処方法を案内します。
主な機能
- 01ビルドと実行のトラブルシューティング
- 02コンテナログと状態の確認
- 03ネットワーク診断
- 04ボリューム権限の対処案
- 05Dockerfileのベストプラクティス
活用シーン
- 01予期せず終了するコンテナの調査
- 02Dockerビルド失敗の原因調査
- 03コンテナ接続問題の診断
- 04ボリューム権限エラーの解消
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ onewave-ai/ claude-skills --skill docker-debuggerインストール後、Claude Code で/docker-debuggerを入力して読み込まれたか確認します。
詳細
Docker デバッガー
手順
Docker の問題をデバッグする場合:
- 問題の種類を特定します:ビルド、実行時、ネットワーク、パフォーマンス
- 診断コマンドを使って情報を収集します
- ログとエラーを分析します
- 修正を適用します
診断コマンド
# Check running containers
docker ps -a
# View container logs
docker logs <container_id> --tail 100 -f
# Inspect container
docker inspect <container_id>
# Check resource usage
docker stats
# View container processes
docker top <container_id>
# Execute shell in running container
docker exec -it <container_id> /bin/sh
# Check Docker disk usage
docker system df
# View build history
docker history <image_name>
よくある問題と解決策
1. コンテナがすぐに終了する
# Check exit code
docker inspect <container_id> --format='{{.State.ExitCode}}'
# View last logs
docker logs <container_id>
修正方法:
- CMD/ENTRYPOINT でフォアグラウンドプロセスを実行するようにします
- 不足している依存関係がないか確認します
- 環境変数を確認します
2. ビルドが失敗する
# Use multi-stage builds for smaller images
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]
3. ネットワークの問題
# List networks
docker network ls
# Inspect network
docker network inspect <network_name>
# Check container IP
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>
4. ボリュームの権限の問題
# Create non-root user
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
# Set ownership
COPY --chown=appuser:appgroup . .
USER appuser
Dockerfile のベストプラクティス
# 1. Use specific tags, not :latest
FROM node:20.10-alpine
# 2. Set working directory
WORKDIR /app
# 3. Copy dependency files first (better caching)
COPY package*.json ./
RUN npm ci --only=production
# 4. Copy source after dependencies
COPY . .
# 5. Use non-root user
USER node
# 6. Set proper labels
LABEL maintainer="[email protected]"
LABEL version="1.0"
# 7. Use HEALTHCHECK
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget -q --spider http://localhost:3000/health || exit 1
# 8. Expose ports
EXPOSE 3000
# 9. Use exec form for CMD
CMD ["node", "server.js"]
docker-compose のデバッグ
# docker-compose.yml
services:
app:
build:
context: .
dockerfile: Dockerfile
# Add for debugging
stdin_open: true
tty: true
# Override command for debugging
command: /bin/sh
volumes:
- .:/app
environment:
- DEBUG=true
# Rebuild without cache
docker-compose build --no-cache
# View logs
docker-compose logs -f app
# Restart single service
docker-compose restart app
コメント
Markdown 対応