Docker Compose
Estimated reading: 4 minutes 39 views

🐳 Mastering Basic Docker Compose Commands – Essential CLI Guide for Beginners

🧲 Introduction – Why Learn Docker Compose Commands?

Docker Compose is more than just a file—it’s your command center for managing multi-container applications. With just a few easy-to-remember commands, you can spin up your full stack, pause services for debugging, clean up resources, or scale as needed.

🎯 In this guide, you’ll explore:

  • The five most important Docker Compose commands
  • Syntax and options with real examples
  • Best practices for service control and orchestration

🔼 docker-compose up – Start Everything

🧠 What Does It Do?

The up command launches and runs all services defined in your docker-compose.yml file. If needed, it also builds the images.

🛠️ Syntax

docker-compose up [OPTIONS] [SERVICE...]

🧰 Key Options

OptionDescription
-dRun in detached mode (in the background)
--buildBuild images before starting containers
--no-depsDon’t start linked services automatically

💡 Example

docker-compose up -d

Output:

Creating network "myapp_default" with the default driver
Creating myapp_web_1 ... done
Creating myapp_db_1  ... done

💡 Pro Tip: Use --build to make sure your latest code changes are reflected.


🔽 docker-compose down – Shut Down & Clean Up

🧠 What Does It Do?

Stops and removes all services, networks, and optionally volumes/images created by up.

🛠️ Syntax

docker-compose down [OPTIONS]

🧰 Key Options

OptionDescription
-vRemove named volumes
--rmi allRemove all images built by Compose
--remove-orphansRemove containers not defined in current config

💡 Example

docker-compose down -v

Output:

Stopping myapp_db_1 ... done
Removing myapp_db_1 ... done
Removing network myapp_default

💡 Pro Tip: Include -v for a clean reset of your volumes and database data.


📋 docker-compose ps – View Container Status

🧠 What Does It Do?

Lists the current status of all services (running, stopped, exited).

🛠️ Syntax

docker-compose ps [OPTIONS]

🧰 Key Options

OptionDescription
-qShow container IDs only
--servicesDisplay only service names

💡 Example

docker-compose ps

Output:

    Name                 Command               State           Ports
-----------------------------------------------------------------------
myapp_web_1   "docker-entrypoint.sh"   Up      0.0.0.0:80->80/tcp
myapp_db_1    "docker-entrypoint.sh"   Up      5432/tcp

💡 Pro Tip: Use -q in scripts for piping container IDs to other commands.


docker-compose stop – Pause Services Without Removal

🧠 What Does It Do?

Gracefully stops all running services but leaves the containers and data intact.

🛠️ Syntax

docker-compose stop [SERVICE...]

👉 No additional flags needed.

💡 Example

docker-compose stop web

Output:

Stopping myapp_web_1 ... done

💡 Pro Tip: Great for debugging or pausing only specific services.


▶️ docker-compose start – Resume Paused Services

🧠 What Does It Do?

Restarts any containers that were stopped with stop, without rebuilding.

🛠️ Syntax

docker-compose start [SERVICE...]

👉 Again, no flags—just simplicity.

💡 Example

docker-compose start web

Output:

Starting myapp_web_1 ... done

💡 Pro Tip: Use it after stop for controlled manual restarts during development.


📊 Command Comparison Table

🧩 Command🔍 Action⚙️ Key Options
docker-compose upBuild and start services-d, --build, --no-deps
docker-compose downStop and remove everything-v, --rmi all, --remove-orphans
docker-compose psShow status of services-q, --services
docker-compose stopStop services without deletingNone
docker-compose startStart previously stopped servicesNone

📌 Summary – Recap & Next Steps

Mastering these basic Docker Compose commands gives you hands-on control over your local development and test environments. Whether you’re starting services, debugging, or tearing things down, these commands are your go-to DevOps tools.

🔍 Key Takeaways:

  • Use up and down to manage full lifecycles
  • Use stop and start for service-level control
  • Use ps to monitor your application’s status

⚙️ Integrating these commands into your daily workflow boosts automation, reduces errors, and accelerates development.


❓ Frequently Asked Questions (FAQs)

🔁 What’s the difference between docker-compose stop and down?

stop halts containers but keeps everything intact.
down removes containers, networks, and optionally volumes/images.


🗑️ Does docker-compose down delete volumes and networks?

Yes—networks are removed by default. To remove volumes, you must add -v.


🔄 Can I restart containers with docker-compose start?

Absolutely! Use start to resume services that were paused with stop.


🚫 What happens if I run up after stop?

Docker Compose will reuse the containers and start them without rebuilding—unless you add --build.


🔄 How is up different from start?

  • up builds, creates, and starts new containers
  • start only restarts stopped containers—no build, no setup

🧱 Will up rebuild images every time?

No. Use --build if you’ve changed the code or Dockerfile.


👀 How do I view logs for my containers?

Use:

docker-compose logs -f

This streams logs in real-time.


🕵️ How do I check running containers?

Run:

docker-compose ps

It shows status, commands, ports, and more.


🧹 How do I completely reset everything?

Run:

docker-compose down -v --rmi all --remove-orphans

This wipes your entire Docker Compose environment clean.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Basic Docker Compose Commands

Or Copy Link

CONTENTS
Scroll to Top