Grafana Loki minimal setup for Docker Swarm.
It is not recommended to use this exact setup for production.
It is supposed to a starting point for people who want to run Grafana and Loki in a Docker Swarm stack.
You will need to adapt it for your requirements.
-
Initialize Docker Swarm
Before deploying the stack to Docker Swarm, ensure that Docker Swarm is initialized. If you are using a single node (your local machine), you can initialize it using:
docker swarm init
If you have multiple nodes, Docker will provide you with a docker swarm join command to run on worker nodes.
-
Config files:
Ensure that the configuration files specified under configs is available in Docker. As they are marked as external, you need to create them in Docker before deploying the stack:
docker config create loki_config ./loki-config.yaml docker config create promtail_config ./promtail-config.yaml
-
Deploying the Stack
Deploy the stack using docker stack deploy.
docker stack deploy -c grafana-loki-stack.yml my-stack
Replace
my-stack
with the name you'd like to give to your stack. -
Viewing test logs
For testing purposes, flog creates log entries every second. To view them in Grafana, follow these steps:
- Find out the flog container name:
Replace
docker inspect $(docker ps -q -f name=<my_stack>_flog) | jq -r '.[0].Name' | sed 's/^\///'`
<my-stack>
with the actual stack name you have chosen. - In Grafana, go to "Connections > Datasources > Loki > Explore" and click on "code".
Enter this as query code:
Replace
{container="<flog_container_name>"}
<my-flog_container_name>
with the actual container name.
- Find out the flog container name:
-
Accessing Grafana
Once deployed, you should be able to access Grafana on http://localhost:3000 (or using your Docker node’s IP address).
-
Removing the Stack
When you want to remove the stack:
docker stack rm my-stack
Notes:
- Ensure Docker is running in swarm mode and your node is active.
- Ensure that all path references and external configurations are available and accurate.
- Always validate the configuration file using docker-compose config to avoid runtime issues.
- Monitor logs for loki and grafana services to troubleshoot any issues during runtime.
With these steps, your services defined in the Docker Compose file should be deployed and managed by Docker Swarm.