Lazy loaded image
Docker Compose
Words 576Read Time 2 min
Jun 4, 2025
Jun 4, 2025
type
status
date
slug
summary
tags
category
icon
password
📌
So what is docker compose ? docker compose is tool for define multi-container that you define by you, and manage it more easy in single .yaml file. Example you need to run Nginx & PostgreSQL you can define it with 2 services nginx & PostgreSQL. and when you need to up date the environment just define it on .yaml file. with docker-compose.yaml making it easy to manage services, networks, and volumes in a single YAML configuration file
 

Why use Compose?

 

Benefits of docker compose

  • Simplified control
  • Efficient collaboration
  • Rapid application development
  • Portability across environments
  • Extensive community and support
 

Example

Running simple apps behind proxy (Caddy). Create docker-compose.yaml and Caddyfile in same folder
 
use nano or any text editor to create it
save with ctrl+x and y to save
 
with docker compose file in these i am want run 2 apps with image caddy:2 and hashicorp/http-echo and to run it just use docker compose up -d your app will automatically run. its will download the container image if you don't have it, and runt 2 apps in same time
 
lets try to run it
docker compose up -d
after finish you can see its running
notion image
and you can check your container app running with define in our compose.yaml
notion image
its defined from our compose and if you need changes you can update the docker-compose.yaml example changes. is change container name
and when run docker compose up -d its make changes to our previous docker container
notion image
name container changes from caddycaddy_http_server its make an update on the container easy. so even the normal way make changes without compose can do it like rename container, not all things can do by docker command its self.

Things you can change (without recreating the container):

Change Type
Command
Container name
docker rename old_name new_name
Resource limits (some)
docker update --memory 512m container_name
Restart policy
docker update --restart=always container_name
CPU shares/limits
docker update --cpus=1 container_name
Labels (in limited ways)
Only via docker commit + new container
Environment (inside)
You can docker exec and change environment manually, but it's not persistent
Files/configs inside the container
Use docker exec, docker cp, or bind mounts
Volumes (mount new ones)
docker cp to move files in/out, but volumes themselves are set at creation

Things you cannot change (must recreate container):

Change
Why?
Published ports (-p)
Docker’s port bindings are fixed at start time
Environment variables (-e)
Set at container creation
Command or entrypoint
Set at creation (CMD, ENTRYPOINT)
Volume definitions (-v)
Must be defined at container start
Network mode (--network)
Set at container start
Image version
You need to pull a new image and re-run
so its will crucial if our app cannot make any changes.
 
Example

🚫 Without Docker Compose

 
You’d have to run each container manually
Disadvantages:
  • Have to manually manage each container.
  • Must ensure correct start order (e.g., DB before app).
  • No easy way to define a full environment in one file.
  • Harder to replicate the setup on another machine or server.
 

✅ With Docker Compose

Run with:
Advantages:
  • 📝 Declarative configuration: All setup in one YAML file.
  • 🧩 Easy orchestration: Automatically handles dependencies like DB.
  • 🔁 Reproducibility: Easily version-controlled, shared, and deployed.
  • 🧼 Cleaner CLI: One command to bring the whole app up or down.
  • 🛠️ Scalability: Easily scale services (docker-compose up --scale).
  • 🧪 Better for testing: Great for CI pipelines and local dev environments.
 

✅ Summary Table

Feature
Without Compose
With Compose
Manual container start
❌ (one command)
Easy config reuse/version
Multi-service support
🔧 Manual
✅ Native
Dependency management
✅ (depends_on)
Networking between services
Manual setup
Auto-managed
Portability
And in my opinion i more like to use compose if to manage multiple container. its easy whenever i want to update or configure env
上一篇
Install Debian Desktop in Huawei Matepad
下一篇
Deploy Jenkins with Docker