Simple two-service stack with port publishing and environment variables.

Section: compose.yaml Basics

Minimal web + db stack

yaml
yaml
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
Explanation

A good starting point for local dev stacks.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing compose.yaml Basics
Service built from Dockerfile
Build a service image from local source while also tagging it.
OpenIn sheetyamlsame section
Override service command
Runs a different default command than the image CMD.
OpenIn sheetyamlsame section
Override entrypoint
Overrides the image entrypoint.
OpenIn sheetyamlsame section
Set explicit container name
Pins a specific container name.
OpenIn sheetyamlsame section
Environment as key/value map
Provide container environment values inline in YAML.
OpenIn sheetyaml2 tag match
Define optional profiles
Marks a service as optional unless its profile is enabled.
OpenIn sheetyaml2 tag match