Docker

Grafana Docker Compose

Grafana is an open-source platform used for monitoring devices and infrastructure. Grafana provides a flexible and user-friendly interface for visualizing and analyzing data from various sources, such as databases, cloud services, and IoT devices.

In this short tutorial, we will quickly walk you through the process of setting up a basic Grafana instance using Docker compose.

Requirements

To run the commands and steps provided in this post, ensure you have the following:

  1. Docker engine installed
  2. Docker compose installed
  3. Sufficient permissions to run Docker containers

Defining Docker Compose File

The first step is defining the Docker compose configuration for running the Docker container. Start by creating the directory to store the config file:

$ mkdir grafana

Navigate into the directory and create a file called docker-compose.yml file.

$ cd grafana

$ touch docker-compose.yml

Edit the file and add the configuration as shown:

version: '3.8'
services:
  grafana:
    image: grafana/grafana-enterprise
    container_name: grafana
    restart: unless-stopped
    ports:
      - '3000:3000'
    volumes:
      - grafana_data:/var/lib/grafana
volumes:
  grafana_data: {}

In the above Docker Compose configuration file, we define all the steps and configuration for deploying a Grafana container.

We start by defining the version of the Docker compose format. We then define the Grafana service, which includes all the required services. For example, we tell Docker to use Grafana enterprise image.

We also specify other service features, such as the restart policy, port mapping to port 3000, and more.

Finally, to ensure data persistency, we create a volume named grafana_data, which stores data in /var/lib/grafana.

Running the Container

Once we are satisfied with the configuration, we can use the docker compose utility to run the container as:

$ docker compose up -d

Accessing Grafana

Once the containers are started, you can access the Grafana instance by navigating to the address: http://localhost:3000.

This should prompt you to provide the default credentials. Use the admin/admin combination. Once logged in, you will be forced to change the password for the admin account.

Conclusion

This tutorial covered the basics of setting up a Grafana instance by using the Docker container and the Grafana enterprise image. Feel free to reference the documentation for more details and customization.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list