Skip to content
An`s Weblog
Go back

Compose Commands

1. Cấu trúc file docker-compose.yml

4 top-level keys chính:

version: "3"

2. Ví dụ file docker-compose.yml mẫu

version: "3"

services:
  weather-app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - VERSION=v2.0
    ports:
      - "8081:3000"
    environment:
      - NODE_ENV=production
    container_name: weather1

3. Các lệnh thao tác

LệnhÝ nghĩa
docker-compose up -dBuild (nếu chưa có) + run container
docker-compose psLiệt kê container được compose tạo
docker-compose buildBuild lại image từ Dockerfile
docker-compose build --no-cacheBuild lại, bỏ qua cache
curl localhost:8081Kiểm tra app đã chạy chưa

4. Các khái niệm mới

5. Thực hành

1. Clone repo:

git clone <repo-url> weather-app
cd weather-app
git checkout compose

2. Viết file docker-compose.yml như trên.

3. Build & run:

docker-compose up -d

4. Kiểm tra:

docker-compose ps
curl localhost:8081

5. Rebuild khi Dockerfile đổi:

docker-compose build
## hoặc
docker-compose build --no-cache

Kết luận


Share this post:

Previous Post
Creating a Compose File
Next Post
Installing Docker Compose