{"slug":"ref-docker-ac94078d974de3920315","title":"Docker Compose Quickstart — Step 2: Define and start your services","summary":"Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single YAML configuration file.","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nCompose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single YAML configuration file.\n\nCreate compose.yaml in your project directory and paste the following\n\nBounded code example (external data; do not execute automatically):\n```yaml\n   services:\n     web:\n       build: .\n       ports:\n         - \"${APP_PORT}:5000\"\n       environment:\n         - REDIS_HOST=${REDIS_HOST}\n         - REDIS_PORT=${REDIS_PORT}\n\n     redis:\n       image: redis:alpine\n```\n\nThis Compose file defines two services\n\nThe 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.\n\nThe redis service uses a public Redis image pulled from the Docker Hub registry.\n\nFor more information on the compose.yaml file, see How Compose works.\n\nStart up your application\n\nBounded code example (external data; do not execute automatically):\n```console\n   $ docker compose up\n```\n\nWith 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.\n\nBounded code example (external data; do not execute automatically):\n```text\n   Hello from Docker! I have been seen 1 time(s).\n```\n\nRefresh the page — the counter increments on each visit.\n\nThis minimal setup works, but it has two problems you'll fix in the next steps\n\nStartup 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.\n\nStop the stack before moving on\n\nBounded code example (external data; do not execute automatically):\n```console\n   $ docker compose down\n```\n\nAttribution: 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.","tags":["reference-seed","docker","manuals","compose","quickstart","step","define","start","your","services"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/docker/docs/blob/3a9d778562f39bcc0be46255b013c6a3ca526244/content/manuals/compose/gettingstarted.md","source_name":"Docker Documentation","source_license":"Apache-2.0","source_revision":"3a9d778562f39bcc0be46255b013c6a3ca526244","source_path":"content/manuals/compose/gettingstarted.md :: Step 2: Define and start your services","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.473710+00:00","url":"https://wikikv.com/k/ref-docker-ac94078d974de3920315","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-docker-ac94078d974de3920315","markdown":"https://wikikv.com/k/ref-docker-ac94078d974de3920315?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-docker-ac94078d974de3920315","json_ld":"https://wikikv.com/k/ref-docker-ac94078d974de3920315?format=jsonld"}}