EN: Read in English
Dunia D4: Set Hidangan
Tambahan pilihan: profiles
Anda akan belajar: biarkan hidangan tambahan tutup sampai anda memintanya.
Teks BM belum disemak oleh penutur asli.
Disemak dengan Docker Engine 29 pada 31 Okt 2026
Masalahnya
Laptop anda~/kedai-kancil
- Tiada tingkap terbuka
Bekas (container)
- Belum ada container
Pek beku (image)
- kedai-kancil-api:latest6 layer · 244MB
- kedai-kancil-web:latest9 layer · 92.6MB
- nginx:1.30-alpine8 layer · 93.5MB
- node:24-alpine4 layer · 244MB
- postgres:18-alpine9 layer · 433MB
- redis:8-alpine7 layer · 162MB
0 container (0 berjalan), 6 image, 0 loker.
Cache ada dalam compose.yaml. Anda dah jalankan docker compose up -d. Jadi kenapa ia tak berjalan?
Tengok
cache:
image: redis:8-alpine
profiles: [cache]Lauk tambahan datang hanya bila anda minta. Itulah profile: Lauk tambahan: service yang hidup hanya bila diminta, dengan --profile atau ikut namanya.. Hidangan yang ada profile kekal tutup. Anda hidupkannya bila perlu. Susun hidangan ini.
Seret kad ke dalam kotak. Atau ketik kad, kemudian ketik kotak.
Cuba
Pesan lauk tambahan juga. Hidupkan profile cache.
Laptop anda~/kedai-kancil
- Port laptop 8080 → kedai-kancil-web-1 port 80
Bekas (container)
- kedai-kancil-api-1berjalan
- kedai-kancil-db-1berjalan
- kedai-kancil-web-1berjalan
Pek beku (image)
- kedai-kancil-api:latest6 layer · 244MB · sedang diguna
- kedai-kancil-web:latest9 layer · 92.6MB · sedang diguna
- nginx:1.30-alpine8 layer · 93.5MB
- node:24-alpine4 layer · 244MB
- postgres:18-alpine9 layer · 433MB · sedang diguna
- redis:8-alpine7 layer · 162MB
Loker (volume)
- kedai-kancil_db-data24 fail · diguna oleh kedai-kancil-db-1
Talian telefon (rangkaian)
- kedai-kancil_defaultkedai-kancil-api-1 ↔ kedai-kancil-db-1 ↔ kedai-kancil-web-1
3 container (3 berjalan), 6 image, 1 loker.
Petunjuk
docker compose --profile cache up -dTeka
Langsung tiada --profile. Anda taip docker compose up -d cache. Apa jadi?
Pilih satu jawapan.
Semak
Laptop anda~/kedai-kancil
- Tiada tingkap terbuka
Bekas (container)
- Belum ada container
Pek beku (image)
- kedai-kancil-api:latest6 layer · 244MB
- kedai-kancil-web:latest9 layer · 92.6MB
- nginx:1.30-alpine8 layer · 93.5MB
- node:24-alpine4 layer · 244MB
- postgres:18-alpine9 layer · 433MB
- redis:8-alpine7 layer · 162MB
0 container (0 berjalan), 6 image, 0 loker.
Hati-hati masa tutup kedai. down biasa hanya kemas hidangan tanpa profile. Tambah --profile cache untuk kemas lauk tambahan juga.
Anda berjaya!
Kini anda boleh biarkan hidangan tambahan tutup sampai anda memintanya.
Nak tahu lebih (pilihan)
COMPOSE_PROFILES=cache docker compose up -d buat perkara sama seperti pilihan itu. Hidupkan dua dengan --profile cache --profile debug. Lauk tambahan yang sesuai: alat debug, laman admin, kerja yang muatkan data ujian. Nama profile guna huruf, nombor, _, . dan -.
Misi sebenar
docker compose config --servicesdocker compose --profile cache config --services
0 daripada 3 langkah siap · Tanda anda disimpan.
English
The cache is right there in compose.yaml. You ran docker compose up -d. So why is it not running?
cache:
image: redis:8-alpine
profiles: [cache]A side dish comes only when you ask for it. That is a profile. A dish with a profile stays off. You turn it on when you need it. Sort the dishes.
Order the side dish too. Turn on the cache profile.
docker compose --profile cache up -dNo --profile at all. You type docker compose up -d cache. What happens?
Careful at closing time. Plain down only clears dishes without a profile. Add --profile cache to clear the side dish too.
You can now keep extra dishes off until you ask for them.
Anda dah siapkan ini. Latihan lagi pun bagus!
Dokumentasi rasmi: Using profiles with Compose · Compose file reference: profiles
Anda dah belajar 25 minit. Rehat sekejap bantu otak anda.
Pecutan selesai! Fokus yang hebat. Regangkan badan seminit?