本文へスキップ
Skillpedia
デプロイとクラウド(DevOps)48k · #4474

docker-compose

できること

Docker Composeは、一緒に動かす必要がある複数のプログラム(サービス)を管理するツールです。テキストファイルに、それらのプログラムとその接続方法をまとめて記述するため、複雑なアプリケーションを動かしやすくなります。

使う場面

  • ✓連携して動く必要がある複数のプログラムがあるとき(例:Webサイトとデータベース)。
  • ✓本番環境と同じ構成のテスト環境を作りたいとき。
  • ✓チーム全員が同じ設定を使えるようにしたいとき。

スキルのリンク

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/docker-compose/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/docker-compose/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“「Docker Composeを使って、Webサイトとデータベースの環境を構築してください。」”

毎週5つの新しいスキル。1分で読めます。

仕組み

「docker-compose.yml」というファイルに、各プログラム(サービス)、使用するイメージ、必要なポート、他のプログラムとの接続方法を記述します。その後、簡単なコマンドを実行するとすべてが起動します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Docker Compose

Orchestrate multi-container applications with declarative YAML configuration.

When to Use This Skill

Use this skill when:

  • Running multi-container applications locally
  • Setting up development environments
  • Defining service dependencies and networking
  • Managing application stacks with multiple services
  • Creating reproducible development setups

Execution Scope

Confirm the selected Docker context and project before any operation. Build instructions execute contributed commands; inspect the Dockerfile, build context, scripts and downloaded dependencies first. Image publication, shared-container stops and volume deletion need authorization for the exact target. Do not expose environment values, image history or logs containing credentials. These examples are independent fragments with project-specific assets, not a complete deployment.

Prerequisites

  • Docker Engine with Compose plugin (v2)
  • Basic Docker knowledge
  • YAML syntax understanding

Basic Configuration

Simple Application Stack

# docker-compose.yml

services:
  web:
    build: .
    ports:
      - "127.0.0.1:3000:3000"
    environment:
      - NODE_ENV=development
      - DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD:?set a local fixture password}@db:5432/myapp
    depends_on:
      - db
      - redis

  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set a local fixture password}
      POSTGRES_DB: myapp
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "127.0.0.1:5432:5432"

  redis:
    image: redis:7-alpine
    ports:
      - "127.0.0.1:6379:6379"

volumes:
  postgres-data:

Service Configuration

Build Options

services:
  app:
    build:
      context: ./app
      dockerfile: Dockerfile.dev
      args:
        NODE_VERSION: "20"
      target: development
      cache_from:
        - myapp:cache
    image: myapp:dev

Environment Variables

services:
  app:
    environment:
      - NODE_ENV=production
      - API_KEY=${API_KEY}  # From shell or .env file
    env_file:
      - .env
      - .env.local

Port Mapping

services:
  web:
    ports:
      - "127.0.0.1:3000:3000"           # HOST:CONTAINER
      - "127.0.0.1:9229:9229" # Bind to localhost only
      - "8080-8090:8080-8090" # Port range
    expose:
      - "3000"                # Internal only (no host binding)

Volume Mounts

services:
  app:
    volumes:
      # Named volume
      - app-data:/app/data
      # Bind mount
      - ./src:/app/src
      # Read-only bind mount
      - ./config:/app/config:ro
      # Anonymous volume (for node_modules)
      - /app/node_modules

volumes:
  app-data:
    driver: local

Dependencies

services:
  web:
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

Networking

Custom Networks

services:
  frontend:
    networks:
      - frontend-net

  backend:
    networks:
      - frontend-net
      - backend-net

  db:
    networks:
      - backend-net

networks:
  frontend-net:
    driver: bridge
  backend-net:
    driver: bridge
    internal: true  # No external access

Network Aliases

services:
  db:
    networks:
      backend:
        aliases:
          - database
          - postgres

networks:
  backend:

Resource Limits

services:
  app:
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 1G
        reservations:
          cpus: '0.5'
          memory: 256M

Multiple Compose Files

Override Files

# docker-compose.yml (base)
services:
  web:
    image: myapp:latest
    ports:
      - "127.0.0.1:3000:3000"

# docker-compose.override.yml (development - auto-loaded)
services:
  web:
    build: .
    volumes:
      - ./src:/app/src
    environment:
      - DEBUG=true

# docker-compose.prod.yml (production)
services:
  web:
    deploy:
      replicas: 3
    environment:
      - DEBUG=false

Using Multiple Files

# Development (uses override automatically)
docker compose up

# Production
docker compose -f docker-compose.yml -f docker-compose.prod.yml up

# Merge and view final config

…
よくある質問

Docker Composeの「サービス」とは何ですか?

Webサーバー、データベース、キャッシュなど、アプリケーションを構成し一緒に動かす必要がある個々のプログラムや部品のことです。

「ボリューム」とは何ですか?

アプリケーションの重要なデータを保存する場所です。プログラムを再起動したり削除したりしても、データは残ります。プログラムのためのハードディスクのようなものです。

Docker Composeを使って、自分のアプリケーションをインターネット上で公開できますか?

Docker Composeは、ローカルや自分で管理するサーバーでアプリケーションを動かすのに適しています。インターネット上で規模に応じて拡張して運用するには、別のツールの方が適している場合もありますが、Composeは良い出発点になります。

詳細

作者による元の説明

Define and run multi-container Docker applications using Docker Compose.

repo: sickn33/agentic-awesome-skills

人気

GitHubのスター
48k
ランキング
#4474
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル