Skip to content

Grafana

Grafana Docker: run it with docker run or Docker Compose

Run Grafana in Docker with docker run or Compose, keep dashboards on a volume, fix user 472 errors and add Prometheus. Or use managed Grafana.

· $20 a month on Zenith · No Docker or reverse proxy

Deploy with Zenith

The short version

Use managed Grafana on Zenith if

  • You want Grafana on a public HTTPS address without setting up a domain, reverse proxy and certificates.
  • You don't want to look after the server, the volume and image updates.
  • You want a flat $20 a month with no charge per user.
  • Your data sources are on a private network. [Zenith Enterprise](/enterprise) can run Grafana on your own infrastructure.

Run it in Docker yourself if

  • You need Grafana Enterprise features. They need the grafana/grafana-enterprise image and a licence from Grafana Labs, and Zenith runs the standard grafana/grafana image.

Run Grafana with docker run

These steps follow Grafana's own Docker guide. You need a machine with Docker installed.

  1. 1

    Create a volume

    Grafana keeps dashboards, users and data sources in an SQLite database under /var/lib/grafana. Without a volume, all of it is lost when the container is removed.

    docker volume create grafana-storage
  2. 2

    Start the container

    This runs the standard image in the background on port 3000. Grafana's docs default to grafana/grafana-enterprise, which includes everything in the standard image. Swap the image name if you prefer it.

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

    Sign in and change the password

    Open http://localhost:3000, or your server's IP address on port 3000. Enter admin as the username and the password. Grafana then asks you to choose a new password.

Run Grafana with Docker Compose

Compose keeps the same settings in a file, so upgrades and restarts are one command. Save this as compose.yaml.

services: grafana: image: grafana/grafana container_name: grafana restart: unless-stopped ports: - "3000:3000" environment: GF_SERVER_ROOT_URL: https://grafana.example.com/ volumes: - grafana_storage:/var/lib/grafana volumes: grafana_storage: {}

Start it with docker compose up -d and stop it with docker compose down. To upgrade, pull the new image with docker compose pull and run docker compose up -d again.

Fix "permission denied" and user 472 errors

The Grafana image runs as the grafana user, ID 472, rather than root. Named Docker volumes work as they are. A folder from your host is the usual problem: it belongs to your user, so Grafana stops with an error that /var/lib/grafana is not writable or that it can't create /var/lib/grafana/plugins.

Pick one fix:

  • Use a named volume, as in the commands above.
  • Run Grafana as your own user. This is the bind-mount example from Grafana's docs:
mkdir data docker run -d -p 3000:3000 --name=grafana \ --user "$(id -u)" \ --volume "$PWD/data:/var/lib/grafana" \ grafana/grafana
  • Give the folder to user 472 with sudo chown -R 472:472 data. Run it on the folder on your host, not inside the container.

Choose an image and add plugins

Both grafana/grafana and grafana/grafana-enterprise come in Alpine, Ubuntu and Distroless builds. Alpine is the default. Add -ubuntu to the tag, for example grafana/grafana:<version>-ubuntu, if you need tools Alpine lacks. Pin a version tag in production so an upgrade only happens when you choose.

To install plugins when the container starts, list them in GF_PLUGINS_PREINSTALL, separated by commas. Add @version to pin one, such as [email protected].

Run Prometheus and Grafana together in Docker

Grafana needs something to read from. Prometheus is the usual partner for metrics. Add it to the same compose.yaml and keep its config in a prometheus.yml next to it.

prometheus: image: prom/prometheus ports: - "9090:9090" volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml

In Grafana, add a Prometheus data source with the address http://prometheus:9090. Containers in the same Compose project reach each other by service name.

Connect a data source

Grafana draws dashboards from data stored elsewhere. In Grafana, open Connections, then Data sources, and add Prometheus, Loki, PostgreSQL, MySQL or another source. Give it the source's address, click Save & test, then build a dashboard or import one from Grafana's library.

A Grafana dashboard with time series panels
A Grafana dashboard built from a connected data source.

Managed Grafana: what you skip

The commands above get Grafana running on one machine. Putting it online for a team takes more.

On your own serverOn Zenith
ServerRent or keep a machine running, and install DockerIncluded
StorageCreate and look after the /var/lib/grafana volume5 GB included
SettingsEdit grafana.ini on the serverEdit grafana.ini in the Configuration tab
Web addressA domain, a reverse proxy, HTTPS certificates and GF_SERVER_ROOT_URLIncluded, and GF_SERVER_ROOT_URL already matches
First sign-inSign in as admin/admin and change the passwordA generated admin password, shown under Your credentials
UpdatesPull new images and restartHandled for you
BackupsCopy the volume somewhere safeManaged backups, best effort

Deploy managed Grafana on Zenith

  1. 1

    Click Deploy now on the Grafana page

    Open Grafana in the catalogue and click Deploy now. It costs $20 a month. If you don't have a Zenith account yet, you create one after paying.

  2. 2

    Choose an address

    Pick a name, such as grafana. Your address becomes the name, a hyphen and your username, ending in .zh.run. Click Use this address.

  3. 3

    Sign in

    When the checklist reads that Grafana is live, copy the admin username and password listed under Your credentials, then click Open. The same details stay in the Credentials tab of your dashboard.

  4. 4

    Add your data sources

    Open Connections, then Data sources, and add your sources as above. Grafana on Zenith runs on the internet, so each source needs an address it can reach. A Prometheus on your home network won't work unless you expose it securely. If your sources only live on a private network, Zenith Enterprise can run Grafana on your own infrastructure instead.

Edit grafana.ini on Zenith

Open Grafana in your dashboard, go to the Configuration tab and choose grafana.ini under Files. It starts as Grafana's sample file, with most settings commented out. Change what you need and click Apply & restart. Grafana restarts and reads the saved file.

For example, this makes the light theme the default:

[users] default_theme = light

Zenith sets the server domain, root URL and admin login with environment variables, and those take precedence over the file. Leave http_port at 3000.

Want Grafana without the server?

Zenith runs Grafana for you on its own HTTPS address for $20 a month. Bring your data sources and start building dashboards.

Deploy with Zenith

Common questions

How much does Grafana cost?
On Zenith it costs $20 a month for the whole team. If you run it in Docker yourself, you pay for the machine it runs on. The grafana/grafana-enterprise image can later be upgraded to Grafana's paid features.
Why does Grafana say /var/lib/grafana is not writable?
The image runs as user 472, not root. A host folder you bind-mount is usually owned by your own user, so Grafana can't write to it. Use a named volume, run the container with --user "$(id -u)", or chown the folder to 472.
What is the default Grafana login?
In a fresh Docker install, the username and password are both admin. Grafana asks you to change the password after you sign in. On Zenith, the admin password is generated for you and shown under Your credentials.
Where does Grafana keep its data in Docker?
In /var/lib/grafana inside the container, in an SQLite database. Mount a volume there, or your dashboards and users are lost when the container is removed.
Should I use grafana/grafana or grafana/grafana-enterprise?
Grafana's docs recommend the Enterprise image. It includes everything in grafana/grafana and can be upgraded to paid features later. Use grafana/grafana if you don't need the option to upgrade.
Does managed Grafana on Zenith store my metrics?
No. Grafana shows data from your own sources, such as Prometheus, Loki or a database. Those sources need an address Grafana can reach over the internet.