How to Run Grafana OSS in Docker and Docker Compose

Run Grafana OSS in Docker and Docker Compose: use the grafana/grafana image, preinstall plugins, persist data with volumes, and log in to build dashboards.

Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.

Grafana connects with every possible data source, commonly referred to as databases such as Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL etc. Grafana being an open source solution also enables us to write plugins from scratch for integration with several different data sources. The tool helps us study, analyse & monitor data over a period of time, technically called time series analytics.

In this guide we will learn how to run Grafana using Docker and Docker Compose.

Related content:

Ensure that docker and docker compose is installed

Since we will be using docker to run our set up, it is important that it is installed and running. Please ensure that you have docker installed. If you are using an Ubuntu system, check out this guide on How to Install and Use Docker Engine on Ubuntu 26.04 LTS.

Confirm that docker is working as expected by checking the version:

docker version

Next, ensure that Docker Compose is installed. Compose v2 ships as a Docker CLI plugin (docker compose, with a space) and is bundled with Docker Desktop and the docker-compose-plugin package from Docker’s apt/dnf repositories. Confirm it is available:

docker compose version

The old Python-based docker-compose (v1, installed with pip install docker-compose) reached end of life in 2023 and no longer receives updates. Use the docker compose plugin instead.

Running Grafana in docker

To run Grafana with docker, use the following command. This runs the latest release of Grafana OSS (Grafana 13 at the time of this update).

docker run --name=grafana \
    -p 3000:3000 \
    grafana/grafana:latest

Note: Earlier versions of this guide used the grafana/grafana-oss image. Starting with Grafana 12.4.0 that Docker Hub repository is no longer updated; grafana/grafana ships the same open source image and is where new releases land. For production, pin a specific version tag (for example grafana/grafana:13.2.4) instead of latest.

You can use the -d argument to start in detached mode. Once the server is started, access it by visiting http://server_ip:3000 in your browser.

Install plugins in the Docker container

You can install official and community plugins listed on the Grafana plugins page or from a custom URL.

Install official and community Grafana plugins

Pass the plugins you want installed to Docker with the GF_PLUGINS_PREINSTALL environment variable as a comma-separated list. Grafana installs them when it starts.

docker run -d \
  -p 3000:3000 \
  --name=grafana \
  -e "GF_PLUGINS_PREINSTALL=grafana-clock-panel,yesoreyeram-infinity-datasource" \
  grafana/grafana:latest

Note: If you need to specify the version of a plugin, append it with @. Otherwise, the latest is used. For example: -e "GF_PLUGINS_PREINSTALL=grafana-clock-panel@1.0.1,yesoreyeram-infinity-datasource@3.8.0". To install from a custom URL, use <plugin ID>@[<version>]@<url to plugin zip>.

Older guides use GF_INSTALL_PLUGINS with a space-separated version (grafana-clock-panel 1.0.1). That variable is the legacy method; prefer GF_PLUGINS_PREINSTALL on current Grafana images.

Save your Grafana data

If you do not designate a location for information storage, then all your Grafana data disappears as soon as you stop your container. To save your data, you need to set up persistent storage or bind mounts for your container.

# create a persistent volume for your data in /var/lib/grafana (database and plugins)
docker volume create grafana-storage

# start grafana
docker run -d -p 3000:3000 --name=grafana \
  -v grafana-storage:/var/lib/grafana \
  grafana/grafana:latest

You may want to run Grafana in Docker but use folders on your host for the database or configuration. When doing so, it becomes important to start the container with a user that is able to access and write to the folder you map into the container.

mkdir data # creates a folder for your data
ID=$(id -u) # saves your user id in the ID variable

# starts grafana with your user id and using the data folder
docker run -d --user "$ID" \
  --volume "$PWD/data:/var/lib/grafana" \
  -p 3000:3000 \
  grafana/grafana:latest

Using Docker Compose to run Grafana

We can add the instructions above to a docker compose file to make it easy for us to create, update and manage the deployments. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Add the following to a compose.yaml file (Compose also still reads docker-compose.yaml):

networks:
  grafana:

volumes:
  grafana-storage:

services:
  grafana:
    image: grafana/grafana:latest
    restart: unless-stopped
    ports:
      - 3000:3000
    volumes:
      - grafana-storage:/var/lib/grafana
    networks:
      - grafana

The top-level version: key used in older Compose files is obsolete; Compose v2 ignores it and prints a warning. The named volume grafana-storage avoids the permission errors you get when bind-mounting a host folder without setting user: (the Grafana container runs as UID 472).

Save the file in the directory with the configurations then start the services with this command:

docker compose up

Or you can add the -d argument for detached mode. Since we are binding the same ports, you can access in the same way as listed above.

Logging in to Grafana

Since we mounted the port to localhost:3000, head over to that url in your browser.

Login with your admin user (default admin/admin). You will be prompted to change your password the first time you login.

Conclusion

In this guide we managed to run Grafana using Docker and Docker Compose. You can now add data sources and create graphs.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy