Running Grafana in a Docker Container with Docker Compose

Grafana (https://grafana.com) is a powerful open-source platform for data visualization and analytics. In this guide, I will show you how to run Grafana in a Docker container using Docker Compose.

Prerequisites

Before we begin, ensure you have Docker installed on your system. If not, you can install Docker from the official Docker website.

Create a Docker Compose File

Create a new file named docker-compose.yml in your desired directory and add the following content:

version: '3'
services:
  grafana:
    image: grafana/grafana-oss:11.4.0
    container_name: grafana
    restart: unless-stopped
    user: '0'  # Use '0' for root, or find your user ID with 'id -u'
    ports:
      - '3000:3000'
    volumes:
      - '$PWD/data:/var/lib/grafana'

Start Grafana

  1. Open your terminal
  2. Navigate to the directory containing your docker-compose.yml
  3. Run the following command:
docker-compose up -d

Access Grafana

  1. Open your web browser
  2. Navigate to http://localhost:3000
  3. Log in with these default credentials:
    • Username: admin
    • Password: admin
  4. Follow the prompts to set a new admin password
  5. You’ll be redirected to the Grafana dashboard

Conclusion

Congratulations! You now have Grafana running in a Docker container. You can start exploring its powerful data visualization and analytics capabilities.