3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose

🛠️ Problem: Too Many docker run Commands

Right now, you have Docker images for three microservices:

accounts
loans
cards

To run each one, you’d normally do:

docker run -p <port>:<port> <image-name>

But imagine …


This content originally appeared on DEV Community and was authored by SOVANNARO

🛠️ Problem: Too Many docker run Commands

Right now, you have Docker images for three microservices:

  • accounts
  • loans
  • cards

To run each one, you’d normally do:

docker run -p <port>:<port> <image-name>

But imagine doing that for 100 microservices or even just multiple instances.
đź’ˇ Manually running each with docker run becomes slow and painful.

âś… Solution: Use Docker Compose

What is Docker Compose?

Docker Compose is a tool that lets you:

  • Define all microservices in one YAML file.
  • Start or stop all services with just one command.

👉 Instead of typing docker run multiple times, you write everything once in a file called docker-compose.yml.

⚙️ What Can Docker Compose Do?

  • Start all microservices with docker compose up
  • Stop everything with docker compose down
  • Set memory limits
  • Link services together with a shared network
  • View logs, restart services, and more

Docker Compose is installed automatically with Docker Desktop

đź“„ Let's Create a docker-compose.yml

Put the file anywhere you want (e.g., in your accounts project folder).

Step-by-step Structure:

services:
  accounts:
    image: "your-username/accounts:s4"
    container_name: accounts-ms
    ports:
      - "8080:8080"
    deploy:
      resources:
        limits:
          memory: 700m
    networks:
      - easybank

  loans:
    image: "your-username/loans:s4"
    container_name: loans-ms
    ports:
      - "8090:8090"
    deploy:
      resources:
        limits:
          memory: 700m
    networks:
      - easybank

  cards:
    image: "your-username/cards:s4"
    container_name: cards-ms
    ports:
      - "9000:9000"
    deploy:
      resources:
        limits:
          memory: 700m
    networks:
      - easybank

networks:
  easybank:
    driver: bridge

🔍 Explanation:

Key Meaning
services: Section where you define each microservice
image: The Docker image to use (add your Docker Hub username)
container_name: Give your container a readable name
ports: Map internal ports to your machine
deploy > resources > limits: Restrict memory usage
networks: Allow microservices to talk to each other
easybank (at bottom): Creates a shared network all services use

🤝 Why Use networks:?

Without a shared network, microservices can’t talk to each other.
Adding them to the same network (like easybank) enables communication.

âś… Final Steps

To check if Docker Compose is installed:

docker compose version

If not, visit the Docker Compose install page and follow the steps for your OS.

🎯 What’s Next?

Now that your docker-compose.yml is ready, you can:

Start all services with:

docker compose up

Stop all services with:

docker compose down

đź§  Summary

  • docker-compose.yml lets you manage all services in one file.
  • You define images, ports, memory limits, and networks.
  • Use docker compose up to launch everything with one command.
  • It saves time and avoids manual repetition.


This content originally appeared on DEV Community and was authored by SOVANNARO


Print Share Comment Cite Upload Translate Updates
APA

SOVANNARO | Sciencx (2025-07-26T11:14:27+00:00) 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose. Retrieved from https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/

MLA
" » 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose." SOVANNARO | Sciencx - Saturday July 26, 2025, https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/
HARVARD
SOVANNARO | Sciencx Saturday July 26, 2025 » 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose., viewed ,<https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/>
VANCOUVER
SOVANNARO | Sciencx - » 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/
CHICAGO
" » 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose." SOVANNARO | Sciencx - Accessed . https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/
IEEE
" » 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose." SOVANNARO | Sciencx [Online]. Available: https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/. [Accessed: ]
rf:citation
» 3 Microservices, 1 YAML File, 1 Command: The Power of Docker Compose | SOVANNARO | Sciencx | https://www.scien.cx/2025/07/26/3-microservices-1-yaml-file-1-command-the-power-of-docker-compose/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.