Stream Logs from Docker to Grafana Cloud with Alloy
Setting up logging inside containers can be annoying — especially when logs vanish with the container or you have to mess with volume mounts just to see what's going on. Here's how I made it super simple using Grafana Alloy to send logs from a Flask server running inside a Docker container to Grafana Cloud, without touching host volumes. Quick Demo App: Flask Logger Let's start with a super basic Flask app that just logs requests: # app.py from flask import Flask import logging app = Flask(__name__) logging.basicConfig(filename="liveapi.log", level=logging.INFO) @app.route("/") def hello(): app.logger.info("GET / was hit") return "Hello, World!" if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) This will create a liveapi.log file in the current working directory. ☁️ Set Up Grafana Cloud + Loki Go to Grafana Cloud. Sign up or log in. In the sidebar, go to Connections → Data sources. Search for Loki and set it up. Copy the Loki Push URL from the connection config. It'll look like: https://:@logs-prod-000.grafana.net/api/prom/push You'll use this in Alloy later.

Setting up logging inside containers can be annoying — especially when logs vanish with the container or you have to mess with volume mounts just to see what's going on.
Here's how I made it super simple using Grafana Alloy to send logs from a Flask server running inside a Docker container to Grafana Cloud, without touching host volumes.
Quick Demo App: Flask Logger
Let's start with a super basic Flask app that just logs requests:
# app.py
from flask import Flask
import logging
app = Flask(__name__)
logging.basicConfig(filename="liveapi.log", level=logging.INFO)
@app.route("/")
def hello():
app.logger.info("GET / was hit")
return "Hello, World!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
This will create a liveapi.log
file in the current working directory.
☁️ Set Up Grafana Cloud + Loki
- Go to Grafana Cloud.
- Sign up or log in.
- In the sidebar, go to Connections → Data sources.
- Search for Loki and set it up.
- Copy the Loki Push URL from the connection config. It'll look like:
https://:@logs-prod-000.grafana.net/api/prom/push
You'll use this in Alloy later.