Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

What Is Docker Compose? Run a Multi-Container App From One File

Define services in compose.yaml, start and inspect them with Docker Compose, and understand what happens to data when you stop the project.

Table of Contents

Docker Compose defines and runs an application made of one or more containers. Put the services, networks, and storage in compose.yaml, then use docker compose up to start the project.

Understand the parts

An image contains the software and files used to start a container. A Dockerfile describes how to build an image you own. A Compose file describes how the application’s containers run together, including published ports, settings, and persistent volumes.

Start a local example

Check that Docker and the Compose plugin are available with docker version and docker compose version. For installation, follow Docker’s instructions for your platform. Save the following as compose.yaml in a new directory:

services:
  web:
    image: nginx:alpine
    ports:
      - "127.0.0.1:8080:80"
  cache:
    image: redis:alpine

The web port is published on the local host. Redis has no published host port. The services demonstrate two containers in the same project. The default Nginx page does not use Redis.

docker compose config -q
docker compose up -d
docker compose ps
docker compose logs web

Open http://127.0.0.1:8080 on the Docker host. If port 8080 is occupied, change the host port in the file and rerun up.

Stop or remove the project

docker compose stop stops containers so you can start them again. docker compose down removes the project’s containers and default network. Named volumes are retained by default. Review any volume-removal flag separately because it can delete persistent data. See TipsMake’s Docker course and the storage and volumes lab.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.