Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)48k · #4474

docker-compose

Skill này làm gì

Docker Compose giúp quản lý nhiều chương trình (dịch vụ) cần chạy cùng nhau. Nó dùng một tệp văn bản để mô tả tất cả các chương trình này và cách chúng kết nối, giúp chạy các ứng dụng phức tạp dễ dàng hơn.

Khi nào nên dùng

  • ✓Khi bạn có nhiều chương trình cần hoạt động cùng nhau (ví dụ: một website với cơ sở dữ liệu).
  • ✓Khi bạn muốn tạo môi trường thử nghiệm giống hệt môi trường production.
  • ✓Khi bạn muốn đảm bảo mọi người trong nhóm dùng cùng một cấu hình.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/docker-compose/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thiết lập môi trường với một website và một cơ sở dữ liệu bằng Docker Compose.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn viết một tệp tên “docker-compose.yml” mô tả từng chương trình (dịch vụ), image mà nó dùng, các cổng cần thiết và cách nó kết nối với các chương trình khác. Sau đó, một lệnh đơn giản sẽ khởi động tất cả.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

…
Câu hỏi thường gặp

“Services” trong Docker Compose là gì?

Services là các chương trình hoặc phần khác nhau của ứng dụng cần chạy cùng nhau, như máy chủ web, cơ sở dữ liệu hoặc bộ nhớ đệm.

“Volume” là gì?

Volume là nơi lưu trữ dữ liệu quan trọng của ứng dụng, ngay cả khi chương trình được khởi động lại hoặc xóa đi. Nó giống như một ổ cứng cho chương trình của bạn.

Tôi có thể dùng Docker Compose để chạy ứng dụng trên Internet không?

Docker Compose rất phù hợp để chạy ứng dụng cục bộ hoặc trên máy chủ bạn quản lý. Để chạy trên Internet theo cách có thể mở rộng, các công cụ khác có thể phù hợp hơn, nhưng Compose là điểm khởi đầu tuyệt vời.

Chi tiết

Mô tả gốc của tác giả

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

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4474
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự