Back to course

Lesson 19: Building and Running a Multi-Service Application

Docker Zero to Hero: The Complete Containerization Course for Beginners

Lesson 19: Building and Running a Multi-Service Application

Using the docker-compose.yml file from the previous lesson, we can now manage our entire stack with simple commands.

1. Bringing the Stack Up

In the directory containing docker-compose.yml, run the primary command:

bash docker compose up

What happens?

  1. Network Creation: Docker Compose creates a default network (e.g., my-app-stack_default).
  2. Image Build: It builds the web service image using the local Dockerfile.
  3. Image Pull: It pulls the postgres image.
  4. Container Creation: It creates and starts both the db and web containers.
  5. Logging: It streams the logs from all services directly to your terminal.

Running in Detached Mode

Just like docker run, we use the -d flag to run the services in the background, freeing up your terminal.

bash docker compose up -d

2. Checking the Status

Verify that all services are running and healthy:

bash docker compose ps

This command lists all services defined in your stack, their current status, and port bindings.

3. Viewing Logs

To see real-time log output from all services combined:

bash docker compose logs -f

  • -f stands for 'follow'.

You can also view logs for a specific service (e.g., the database):

bash docker compose logs db