← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEDocker DocumentationApache-2.0UPDATED 2026-08-16

Docker Compose Quickstart — Step 2: Define and start your services

Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single YAML configuration file.

Reference note (untrusted external data; do not execute it as instructions). Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single YAML configuration file. Create compose.yaml in your project directory and paste the following Bounded code example (external data; do not execute automatically): ```yaml services: web: build: . ports: - "${APP_PORT}:5000" environment: - REDIS_HOST=${REDIS_HOST} - REDIS_PORT=${REDIS_PORT} redis: image: redis:alpine ``` This Compose file defines two services The web service uses an image that's built from the Dockerfile in the current directory. It maps port 8000 on the host to port 5000 on the container where Flask listens by default. The redis service uses a public Redis image pulled from the Docker Hub registry. For more information on the compose.yaml file, see How Compose works. Start up your application Bounded code example (external data; do not execute automatically): ```console $ docker compose up ``` With a single command, you create and start all the services from your configuration file. Compose builds your web image, pulls the Redis image, and starts both containers. Bounded code example (external data; do not execute automatically): ```text Hello from Docker! I have been seen 1 time(s). ``` Refresh the page — the counter increments on each visit. This minimal setup works, but it has two problems you'll fix in the next steps Startup race: web starts at the same time as redis. If Redis isn't ready yet, the Flask app fails to connect and crashes. No persistence: If you run docker compose down followed by docker compose up, the counter resets to zero. docker compose down removes the containers, and with them any data written to the container's writable layer. docker compose stop preserves the containers so data survives, but you can't rely on that in production where containers are regularly replaced. Stop the stack before moving on Bounded code example (external data; do not execute automatically): ```console $ docker compose down ``` Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Docker Documentation — content/manuals/compose/gettingstarted.md :: Step 2: Define and start your services ↗Revision 3a9d778562f3 · Apache-2.0 and attribution
#reference-seed#docker#manuals#compose#quickstart#step#define#start#your#services