Grafana is a widely used visualization and analytics solution, especially with the cloud-native applications. Grafana is able to get data from various sources e.g databases (MySQL, PostgreSQL, MongoDB, OpenTSDB, InfluxDB, e.t.c), as well as the cloud services such as AWS CloudWatch, Azure Monitor, and Google Cloud service monitoring.

By using Grafana, you can easily create customizable dashboards with charts, graphs, and alerts, and get a cleaner view of real-time data metrics. Most installations of Grafana will use package managers like APT, and YUM. But in this guide we shall perform installation of Grafana Server in Docker Container. You will need a Docker Engine prior to performing other operations.

Install Docker Engine

See our guides on the installation of Docker Engine.

Check for the version of Docker Engine to confirm installation.

$ docker --version
Docker version 24.0.7, build afdd53b

Create data directories for Grafana

mkdir -p ~/grafana/data

Change your working directory to the created folder.

 cd ~/grafana/

Create Docker volume called grafana-storage

$ docker volume create grafana-storage
grafana-storage

Created volume details can be checked with the volume inspect command.

$ docker volume inspect grafana-storage
[
    {
        "CreatedAt": "2023-12-22T00:56:38+03:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/grafana-storage/_data",
        "Name": "grafana-storage",
        "Options": null,
        "Scope": "local"
    }
]

Run Grafana Server in Docker Container

To run the latest stable version of Grafana using vanilla docker command, run:

docker run -d -p 3000:3000 --name=grafana \
  --volume grafana-storage:/var/lib/grafana \
  grafana/grafana-oss

You can customize the options as below;

  • -d (--detach) is used to run the grafana container in the background
  • -p <host-port>:<container-port> (--publish) publish a container’s port(s) to the host, allowing you to reach the container’s port via a host port. In this case, we can reach the container’s port 3000 via the host’s port 3000
  • --name is used to assign a logical name to the container (e.g. grafana). You can refer a container by the name instead of ID.
  • grafana/grafana-oss is the image to used in running the container

Confirm if the container is running using docker ps command.

$ docker ps
CONTAINER ID   IMAGE                 COMMAND     CREATED          STATUS          PORTS                                       NAMES
1469f991bbd0   grafana/grafana-oss   "/run.sh"   47 seconds ago   Up 39 seconds   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   grafana

To delete the container and volume created run

docker rm -f grafana
docker volume rm grafana-storage

Run Grafana Server using Docker Compose

Docker Compose uses docker-compose.yaml file to define and share applications that consist of multiple containers. With Compose, you can start and stop the containers in the correct order with a single command option. For more information about usage of Docker Compose check Docker Compose Documentation.

Compose plugin for docker must be installed. To determine if this is the case run the following command.

$ docker compose version
Docker Compose version v2.21.0

Create Compose file for running the container

vim docker-compose.yaml

Here are the contents pulled from my Compose file.

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

To run a container with the definitions in the yaml file, run the following command:

$ docker compose up -d
[+] Running 0/0
[+] Running 3/3ana_default  Creating                                                                                                                                                             0.1s
 ✔ Network grafana_default           Created                                                                                                                                                     1.5s
 ✔ Volume "grafana_grafana-storage"  Created                                                                                                                                                     0.1s
 ✔ Container grafana                 Started

Where:

  • d = detached mode
  • up = to bring the container up and running
$ docker compose ps
NAME      IMAGE                 COMMAND     SERVICE   CREATED         STATUS         PORTS
grafana   grafana/grafana-oss   "/run.sh"   grafana   7 minutes ago   Up 7 minutes   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp

Access grafana web interface

Open your web browser http://serverip_or_fqdn:3000. Login with default credentials admin/admin.

Monitor QuestDB Database With Prometheus and Grafana 5

Set new password after login succeed.

install grafana kubernetes 02

Enjoy using Grafana for analytics and general infrastructure monitoring.

Similar articles.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here