{"id":19054346,"url":"https://github.com/datadog/docker-compose-example","last_synced_at":"2025-05-16T12:11:56.314Z","repository":{"id":31548298,"uuid":"35112919","full_name":"DataDog/docker-compose-example","owner":"DataDog","description":"## Auto-archived due to inactivity. ## A working example of using Docker Compose with Datadog","archived":false,"fork":false,"pushed_at":"2024-10-17T10:27:12.000Z","size":5193,"stargazers_count":131,"open_issues_count":10,"forks_count":197,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-12T08:38:31.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataDog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-05T17:05:52.000Z","updated_at":"2025-03-22T00:44:26.000Z","dependencies_parsed_at":"2024-11-23T01:03:12.464Z","dependency_job_id":"8c3d63b9-9dcb-44b6-b024-9d8b059feb53","html_url":"https://github.com/DataDog/docker-compose-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdocker-compose-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdocker-compose-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdocker-compose-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdocker-compose-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataDog","download_url":"https://codeload.github.com/DataDog/docker-compose-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T23:37:57.550Z","updated_at":"2025-05-16T12:11:56.262Z","avatar_url":"https://github.com/DataDog.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using Docker Compose with Datadog\n\nDatadog offers native Docker container monitoring, either by running the Agent\non the host or running in a sidecar container. Which is the best way to run it?\nIt ultimately depends on the tooling you have in place to manage the Agent's\nconfiguration. If you want to go Docker all the way, you can run the Agent as\na sidecar and control its configuration with custom `Dockerfiles`.\n\nLet's see what it looks like.\n\n# Starting off from the Compose example\n\nTo build a meaningful setup, we start from the [example](https://docs.docker.com/compose/#overview)\nthat Docker put together to illustrate Compose. A simple Python web application that\nconnects to Redis to store the number of hits.\n\nHere is the `docker-compose.yml` that powers the whole setup.\n\n```yaml\nversion: \"4\"\nservices:\n  web:\n    build: web\n    command: ddtrace-run python app.py\n    ports:\n     - \"5000:5000\"\n    volumes:\n     - ./web:/code # modified here to take into account the new app path\n    links:\n     - redis\n    environment:\n     - DATADOG_HOST=datadog # used by the web app to initialize the Datadog library\n     - DD_AGENT_HOST=dd-agent # points to dd-agent to send traces\n  redis:\n    image: redis\n  # agent section\n  datadog:\n    container_name: dd-agent\n    build: datadog\n    links:\n     - redis # ensures that redis is a host that the container can find\n     - web # ensures that the web app can send metrics\n    environment:\n     - DD_API_KEY=__your_datadog_api_key_here__\n     - DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true # enables agent to receive custom metrics from other containers\n     - DD_APM_ENABLED=true # enables tracing\n     - DD_APM_NON_LOCAL_TRAFFIC=true # enables agent to receive traces from other containers\n     - DD_AGENT_HOST=dd-agent # allows web container to forward traces to agent\n     - DD_SITE=datadoghq.com # determines datadog instance to send data to (e.g change to datadoghq.eu for EU1)\n    volumes:\n     - /var/run/docker.sock:/var/run/docker.sock\n     - /proc/:/host/proc/:ro\n     - /sys/fs/cgroup:/host/sys/fs/cgroup:ro\n```\n\n# Configuring the Agent\n\nBecause the Agent needs to monitor Redis it needs:\n\n1. The proper `redisdb.yaml` in the container's `/etc/datadog-agent/conf.d` to find the Redis node.\n\nThe Agent's `Dockerfile` takes care of #1.\n\n```\nFROM datadog/agent:latest\nADD conf.d/redisdb.yaml /etc/datadog-agent/conf.d/redisdb.yaml\n```\n\n2. And the Compose yaml files creates the link to Redis with:\n\n```yaml\n  links:\n    - redis\n```\n\n# Configuring APM\n\nThe Agent needs the following in order to collect Python traces from the `web` container:\n\n1. The `ddtrace` library. \n\nThis can be achieved by adding the following to the `requirements.txt` for our `web` app. The `datadog` library is used to collect our custom (`dogstatsd`) metrics\n\n```\nflask\nredis\ndatadog\nddtrace \u003c--\n```\n\n2. Tags that identify the app and its origin. \n\nThis can be achieved by simply adding a few environment variables to the `web` container's `Dockerfile`.\n\n```dockerfile\nFROM python:2.7\nADD . /code\nWORKDIR /code\nRUN pip install -r requirements.txt\n\n# This is where you set DD tags\nENV DD_SERVICE web        \u003c-- This sets the \"service\" name in Datadog\nENV DD_ENV sandbox        \u003c-- This sets the \"env\" name in Datadog\nENV DD_VERSION 1.0        \u003c-- This sets the \"version\" number in Datadog\n```\n\n3. Environment variables \u0026 container name set to ensure connection between your app container and the Agent. \n\nYou will want to make sure that the `DD_AGENT_HOST` environment variables set in your `docker-compose.yml` are the same for both the Agent  and your app container. \n\nAlso set the `container_name` for the `datadog` container to be the same as this `DD_AGENT_HOST` value. \n\n# All in one\n\nHow to test this?\n\n1. [Install Docker Compose](https://docs.docker.com/compose/install/)\n1. Clone this repository\n1. Update your `DD_API_KEY` in `docker-compose.yml`\n1. Run all containers with `docker-compose up`\n1. Refresh `localhost:5000` a few times in your web browser to generate some traces. \n1. Verify in Datadog that your container picks up the Docker \u0026 Redis metrics along with all the APM traces. \n  - An easy way to verify you are receiving these metrics is by visiting the `Metrics Summary` page. Navigate to `Metrics -\u003e Summary`, then search for either `docker` or `redis` to see if any metrics appear. See example below.\n\n  ![metrics_summary](images/metrics_summary.png)\n\n  - An easy way to verify you are receiving APM traces is by visiting the `Trace Explorer` page. Navigate to `APM -\u003e Traces -\u003e Explorer` and you should see a list of traces. If you click on a trace, your flame graph should look like this. \n\n  ![flame_graph](images/flame_graph.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fdocker-compose-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatadog%2Fdocker-compose-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fdocker-compose-example/lists"}