Skip to content

Commit 2484b24

Browse files
marefrxlson
andauthored
Docker: Custom dockerfiles, docker and image rendering docs update (grafana#20492)
Adds support for using custom dockerfiles to pre-install image renderer plugins. Updates docs for docker and image rendering. Fixes grafana#20241 Co-Authored-By: Leonard Gram <[email protected]>
1 parent caff914 commit 2484b24

File tree

9 files changed

+243
-44
lines changed

9 files changed

+243
-44
lines changed

docs/sources/administration/image_rendering.md

+96-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ When an image is being rendered the PNG-image is temporary written to the filesy
1717

1818
A background job runs each 10 minutes and will remove temporary images. You can configure how long time an image should be stored before being removed by configuring the [temp-data-lifetime](/installation/configuration/#temp-data-lifetime) setting.
1919

20-
## Rendering methods
21-
22-
### PhantomJS
20+
## Requirements
2321

24-
> PhantomJS is deprecated since Grafana v6.4 and will be removed in a future release. Please migrate to Grafana image renderer plugin or remote rendering service.
22+
Rendering images may require quite a lot of memory, mainly because there are "browser instances" started in the
23+
background responsible for the actual rendering. Further, if multiple images are being rendered in parallel it most
24+
certainly has a bigger memory footprint. Minimum free memory recommendation is 1GB.
2525

26-
[PhantomJS](https://phantomjs.org/) have been the only supported and default image renderer since Grafana v2.x and is shipped with Grafana.
26+
Depending on [rendering method](#rendering-methods) you would need that memory available in the system where the
27+
rendering process is running. For [Grafana Image renderer plugin](#grafana-image-renderer-plugin) and [PhantomJS](#phantomjs)
28+
it's the system which Grafana is installed on. For [Remote rendering service](#remote-rendering-service) it is the system where
29+
that's installed.
2730

28-
Please note that for macOS and Windows, you will need to ensure that a phantomjs binary is available under tools/phantomjs/phantomjs. For Linux, a phantomjs binary is included - however, you should ensure that any required libraries, e.g. libfontconfig1, are available.
31+
## Rendering methods
2932

3033
### Grafana image renderer plugin
3134

32-
> This plugin currently does not work if it is installed in Grafana docker image.
35+
> This plugin currently does not work if it is installed in the Grafana docker image. See [Install in Grafana docker image](#install-in-grafana-docker-image).
3336
3437
The [Grafana image renderer plugin](https://grafana.com/grafana/plugins/grafana-image-renderer) is a plugin that runs on the backend and handles rendering panels and dashboards as PNG-images using headless chrome.
3538

@@ -39,7 +42,13 @@ You can install it using grafana-cli:
3942
grafana-cli plugins install grafana-image-renderer
4043
```
4144

42-
For further information and instructions refer to the [plugin details](https://grafana.com/grafana/plugins/grafana-image-renderer).
45+
For further information and instructions refer to [troubleshooting](#troubleshooting) and the [plugin details](https://grafana.com/grafana/plugins/grafana-image-renderer).
46+
47+
#### Install in Grafana docker image
48+
49+
This plugin is not compatible with the current Grafana Docker image without installing further system-level dependencies. We recommend setting up another Docker container for rendering and using remote rendering, see [Remote rendering service](#remote-rendering-service) for reference.
50+
51+
If you still want to install the plugin in the Grafana docker image we provide instructions for how to build a custom Grafana image, see [Installing using Docker](/installation/docker/#custom-image-with-grafana-image-renderer-plugin-pre-installed).
4352

4453
### Remote rendering service
4554

@@ -102,7 +111,86 @@ callback_url = http://localhost:3000/
102111
```
103112
4. Restart Grafana
104113

114+
For further information and instructions refer to [troubleshooting](#troubleshooting) and the [plugin details](https://grafana.com/grafana/plugins/grafana-image-renderer).
115+
116+
### PhantomJS
117+
118+
> PhantomJS is deprecated since Grafana v6.4 and will be removed in a future release. Please migrate to Grafana image renderer plugin or remote rendering service.
119+
120+
[PhantomJS](https://phantomjs.org/) have been the only supported and default image renderer since Grafana v2.x and is shipped with Grafana.
121+
122+
PhantomJS binaries are included for Linux (x64), Windows (x64) and Darwin (x64). For Linux you should ensure that any required libraries, e.g. libfontconfig1, are available.
123+
124+
Please note that PhantomJS binaries are not included for ARM. To support this you will need to ensure that a phantomjs binary is available under tools/phantomjs/phantomjs.
125+
105126
## Alerting and render limits
106127

107128
Alert notifications can include images, but rendering many images at the same time can overload the server where the renderer is running. For instructions of how to configure this, see [concurrent_render_limit](/installation/configuration/#concurrent-render-limit).
108129

130+
## Troubleshooting
131+
132+
Enable debug log messages for rendering in the Grafana configuration file and inspect the Grafana server log.
133+
134+
```bash
135+
[log]
136+
filters = rendering:debug
137+
```
138+
139+
### Grafana image renderer plugin and remote rendering service
140+
141+
The plugin and rendering service uses [Chromium browser](https://www.chromium.org/) which depends on certain libraries.
142+
If you don't have all of those libraries installed in your system you may encounter errors when trying to render an image, e.g.
143+
144+
```bash
145+
Rendering failed: Error: Failed to launch chrome!/var/lib/grafana/plugins/grafana-image-renderer/chrome-linux/chrome:
146+
error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory\n\n\nTROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
147+
```
148+
149+
In general you can use the [`ldd`](https://en.wikipedia.org/wiki/Ldd_(Unix)) utility to figure out what shared libraries
150+
are missing/not installed in your system:
151+
152+
```bash
153+
$ cd <grafana-image-render plugin directiry>
154+
$ ldd chrome-linux/chrome
155+
linux-vdso.so.1 (0x00007fff1bf65000)
156+
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2047945000)
157+
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2047924000)
158+
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f204791a000)
159+
libX11.so.6 => not found
160+
libX11-xcb.so.1 => not found
161+
libxcb.so.1 => not found
162+
libXcomposite.so.1 => not found
163+
...
164+
```
165+
166+
**Ubuntu:**
167+
168+
On Ubuntu 18.10 the following dependencies have been confirmed as needed for the image rendering to function.
169+
170+
```bash
171+
libx11-6 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrender1 libxtst6 libglib2.0-0 libnss3 libcups2 libdbus-1-3 libxss1 libxrandr2 libgtk-3-0 libgtk-3-0 libasound2
172+
```
173+
174+
**Centos:**
175+
176+
On a minimal Centos install the following dependencies have been confirmed as needed for the image rendering to function.
177+
178+
```bash
179+
libXcomposite libXdamage libXtst cups libXScrnSaver pango atk adwaita-cursor-theme adwaita-icon-theme at at-spi2-atk at-spi2-core cairo-gobject colord-libs dconf desktop-file-utils ed emacs-filesystem gdk-pixbuf2 glib-networking gnutls gsettings-desktop-schemas gtk-update-icon-cache gtk3 hicolor-icon-theme jasper-libs json-glib libappindicator-gtk3 libdbusmenu libdbusmenu-gtk3 libepoxy liberation-fonts liberation-narrow-fonts liberation-sans-fonts liberation-serif-fonts libgusb libindicator-gtk3 libmodman libproxy libsoup libwayland-cursor libwayland-egl libxkbcommon m4 mailx nettle patch psmisc redhat-lsb-core redhat-lsb-submod-security rest spax time trousers xdg-utils xkeyboard-config
180+
```
181+
182+
#### Using custom Chrome/Chromium
183+
184+
As a last resort, if you already have [Chrome](https://www.google.com/chrome/) or [Chromium](https://www.chromium.org/)
185+
installed on your system you can configure [Grafana Image renderer plugin](#grafana-image-renderer-plugin) to use this
186+
instead of the pre-packaged version of Chromium.
187+
188+
> Please note that this is not recommended since you may encounter problems if the installed version of Chrome/Chromium is not
189+
> is compatible with the [Grafana Image renderer plugin](#grafana-image-renderer-plugin).
190+
191+
To override the path to the Chrome/Chromium executable you can set an environment variable and make sure that
192+
it's available for the Grafana process, e.g.
193+
194+
```bash
195+
export GF_RENDERER_PLUGIN_CHROME_BIN="/usr/bin/chromium-browser"
196+
```

docs/sources/installation/docker.md

+73-32
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ variables by using the syntax `GF_<SectionName>_<KeyName>`.
2525
For example:
2626

2727
```bash
28-
$ docker run \
29-
-d \
28+
$ docker run -d \
3029
-p 3000:3000 \
3130
--name=grafana \
3231
-e "GF_SERVER_ROOT_URL=http://grafana.server.name" \
@@ -53,32 +52,49 @@ GF_PATHS_LOGS | /var/log/grafana
5352
GF_PATHS_PLUGINS | /var/lib/grafana/plugins
5453
GF_PATHS_PROVISIONING | /etc/grafana/provisioning
5554

55+
## Image Variants
56+
57+
The official Grafana Docker image comes in two variants.
58+
59+
**`grafana/grafana:<version>`:**
60+
61+
> **Note:** This image was based on [Ubuntu](https://ubuntu.com/) before version 6.4.0.
62+
63+
This is the default image. This image is based on the popular [Alpine Linux project](http://alpinelinux.org), available in [the alpine official image](https://hub.docker.com/_/alpine). Alpine Linux is much smaller than most distribution base images, and thus leads to slimmer and more secure images.
64+
65+
This variant is highly recommended when security and final image size being as small as possible is desired. The main caveat to note is that it does use [musl libc](http://www.musl-libc.org) instead of [glibc and friends](http://www.etalabs.net/compare_libcs.html), so certain software might run into issues depending on the depth of their libc requirements. However, most software doesn't have an issue with this, so this variant is usually a very safe choice.
66+
67+
**`grafana/grafana:<version>-ubuntu`:**
68+
69+
> **Note:** This image is available since version 6.5.0.
70+
71+
This image is based on [Ubuntu](https://ubuntu.com/), available in [the ubuntu official image](https://hub.docker.com/_/ubuntu).
72+
This is an alternative image for those who prefer an [Ubuntu](https://ubuntu.com/) based image and/or who are dependent on certain
73+
tooling not available for Alpine.
74+
5675
## Running a specific version of Grafana
5776

5877
```bash
59-
# specify right tag, e.g. 5.1.0 - see Docker Hub for available tags
60-
$ docker run \
61-
-d \
62-
-p 3000:3000 \
63-
--name grafana \
64-
grafana/grafana:5.1.0
78+
# specify right tag, e.g. 6.5.0 - see Docker Hub for available tags
79+
$ docker run -d -p 3000:3000 --name grafana grafana/grafana:6.5.0
80+
# ubuntu based images available since Grafana 6.5.0
81+
$ docker run -d -p 3000:3000 --name grafana grafana/grafana:6.5.0-ubuntu
6582
```
6683

6784
## Running the master branch
6885

69-
For every successful build of the master branch we update the `grafana/grafana:master` tag and create a new tag `grafana/grafana-dev:master-<commit hash>` with the hash of the git commit that was built. This means you can always get the latest version of Grafana.
86+
For every successful build of the master branch we update the `grafana/grafana:master` and `grafana/grafana:master-ubuntu`. Additionally, two new tags are created, `grafana/grafana-dev:master-<commit hash>` and `grafana/grafana-dev:master-<commit hash>-ubuntu`, which includes the hash of the git commit that was built. This means you can always get the latest version of Grafana.
7087

7188
When running Grafana master in production we **strongly** recommend that you use the `grafana/grafana-dev:master-<commit hash>` tag as that will guarantee that you use a specific version of Grafana instead of whatever was the most recent commit at the time.
7289

73-
For a list of available tags, check out [grafana/grafana](https://hub.docker.com/r/grafana/grafana/tags/) and [grafana/grafana-dev](https://hub.docker.com/r/grafana/grafana-dev/tags/).
90+
For a list of available tags, check out [grafana/grafana](https://hub.docker.com/r/grafana/grafana/tags/) and [grafana/grafana-dev](https://hub.docker.com/r/grafana/grafana-dev/tags/).
7491

7592
## Installing Grafana plugins
7693

7794
Pass the plugins you want installed to docker with the `GF_INSTALL_PLUGINS` environment variable as a comma separated list. This will pass each plugin name to `grafana-cli plugins install ${plugin}` and install them when Grafana starts.
7895

7996
```bash
80-
docker run \
81-
-d \
97+
docker run -d \
8298
-p 3000:3000 \
8399
--name=grafana \
84100
-e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" \
@@ -87,25 +103,49 @@ docker run \
87103

88104
> If you need to specify the version of a plugin, you can add it to the `GF_INSTALL_PLUGINS` environment variable. Otherwise, the latest will be assumed. For example: `-e "GF_INSTALL_PLUGINS=grafana-clock-panel 1.0.1,grafana-simple-json-datasource 1.3.5"`
89105
90-
## Building a custom Grafana image with pre-installed plugins
106+
## Building a custom Grafana image
107+
108+
In the [Grafana GitHub repository](https://github.com/grafana/grafana/tree/master/packaging/docker) there is a folder called `custom/` which two includes Dockerfiles, `Dockerfile` and `ubuntu.Dockerfile`, that can be used to build a custom Grafana image.
109+
It accepts `GRAFANA_VERSION`, `GF_INSTALL_PLUGINS` and `GF_INSTALL_IMAGE_RENDERER_PLUGIN` as build arguments.
91110

92-
In the [grafana-docker](https://github.com/grafana/grafana/tree/master/packaging/docker) there is a folder called `custom/` which includes a `Dockerfile` that can be used to build a custom Grafana image. It accepts `GRAFANA_VERSION` and `GF_INSTALL_PLUGINS` as build arguments.
111+
### With pre-installed plugins
112+
113+
> If you need to specify the version of a plugin, you can add it to the `GF_INSTALL_PLUGINS` build argument. Otherwise, the latest will be assumed. For example: `--build-arg "GF_INSTALL_PLUGINS=grafana-clock-panel 1.0.1,grafana-simple-json-datasource 1.3.5"`
93114
94115
Example of how to build and run:
95116
```bash
96117
cd custom
97-
docker build -t grafana:latest-with-plugins \
118+
docker build \
98119
--build-arg "GRAFANA_VERSION=latest" \
99-
--build-arg "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" .
120+
--build-arg "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" \
121+
-t grafana-custom -f Dockerfile .
100122

101-
docker run \
102-
-d \
103-
-p 3000:3000 \
104-
--name=grafana \
105-
grafana:latest-with-plugins
123+
docker run -d -p 3000:3000 --name=grafana grafana-custom
106124
```
107125

108-
> If you need to specify the version of a plugin, you can add it to the `GF_INSTALL_PLUGINS` build argument. Otherwise, the latest will be assumed. For example: `--build-arg "GF_INSTALL_PLUGINS=grafana-clock-panel 1.0.1,grafana-simple-json-datasource 1.3.5"`
126+
Replace `Dockerfile` in above example with `ubuntu.Dockerfile` to build a custom Ubuntu based image (Grafana 6.5+).
127+
128+
### With Grafana Image Renderer plugin pre-installed
129+
130+
> Only available in Grafana v6.5+ and experimental.
131+
132+
The [Grafana Image Renderer plugin](/administration/image_rendering/#grafana-image-renderer-plugin) does not
133+
currently work if it is installed in Grafana docker image.
134+
You can build a custom docker image by using the `GF_INSTALL_IMAGE_RENDERER_PLUGIN` build argument.
135+
This will install additional dependencies needed for the Grafana Image Renderer plugin to run.
136+
137+
Example of how to build and run:
138+
```bash
139+
cd custom
140+
docker build \
141+
--build-arg "GRAFANA_VERSION=latest" \
142+
--build-arg "GF_INSTALL_IMAGE_RENDERER_PLUGIN=true" \
143+
-t grafana-custom -f Dockerfile .
144+
145+
docker run -d -p 3000:3000 --name=grafana grafana-custom
146+
```
147+
148+
Replace `Dockerfile` in above example with `ubuntu.Dockerfile` to build a custom Ubuntu based image.
109149

110150
## Installing plugins from other sources
111151

@@ -114,8 +154,7 @@ docker run \
114154
It's possible to install plugins from custom url:s by specifying the url like this: `GF_INSTALL_PLUGINS=<url to plugin zip>;<plugin name>`
115155

116156
```bash
117-
docker run \
118-
-d \
157+
docker run -d \
119158
-p 3000:3000 \
120159
--name=grafana \
121160
-e "GF_INSTALL_PLUGINS=http://plugin-domain.com/my-custom-plugin.zip;custom-plugin" \
@@ -125,8 +164,7 @@ docker run \
125164
## Configuring AWS credentials for CloudWatch Support
126165

127166
```bash
128-
$ docker run \
129-
-d \
167+
$ docker run -d \
130168
-p 3000:3000 \
131169
--name=grafana \
132170
-e "GF_AWS_PROFILES=default" \
@@ -152,12 +190,7 @@ Supported variables:
152190
docker volume create grafana-storage
153191

154192
# start grafana
155-
docker run \
156-
-d \
157-
-p 3000:3000 \
158-
--name=grafana \
159-
-v grafana-storage:/var/lib/grafana \
160-
grafana/grafana
193+
docker run -d -p 3000:3000--name=grafana -v grafana-storage:/var/lib/grafana grafana/grafana
161194
```
162195

163196
## Grafana container using bind mounts
@@ -249,6 +282,14 @@ chown -R root:root /etc/grafana && \
249282
chown -R grafana:grafana /usr/share/grafana
250283
```
251284

285+
## Migration from a previous version of the docker container to 6.4 or later
286+
287+
Grafana’s docker image was changed to be based on [Alpine](http://alpinelinux.org) instead of [Ubuntu](https://ubuntu.com/).
288+
289+
## Migration from a previous version of the docker container to 6.5 or later
290+
291+
Grafana Docker image now comes in two variants, one [Alpine](http://alpinelinux.org) based and one [Ubuntu](https://ubuntu.com/) based, see [Image Variants](#image-variants) for details.
292+
252293
## Logging in for the first time
253294

254295
To run Grafana open your browser and go to http://localhost:3000/. 3000 is the default HTTP port that Grafana listens to if you haven't [configured a different port](/installation/configuration/#http-port).

docs/sources/installation/requirements.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Grafana does not use a lot of resources and is very lightweight in use of memory
3333

3434
Depending on what features are being used and to what extent the requirements varies. Features that consume and requires more resources:
3535

36-
- Server side rendering of images
36+
- [Server side rendering of images](/administration/image_rendering/#requirements)
3737
- [Alerting](/alerting/rules/)
3838
- Data source proxy
3939

docs/sources/installation/upgrading.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,15 @@ is `7.0+` and `max concurrent shard requests` properly configured. 256 was the d
196196

197197
## Upgrading to v6.4
198198

199+
### Annotations database migration
200+
199201
One of the database migrations included in this release will merge multiple rows used to represent an annotation range into a single row. If you have a large number of region annotations the database migration may take a long time to complete. See [Upgrading to v5.2](#upgrading-to-v5-2) for tips on how to manage this process.
200202

201-
Plugins that need updating:
203+
### Docker
204+
205+
Grafana’s docker image is now based on [Alpine](http://alpinelinux.org) instead of [Ubuntu](https://ubuntu.com/).
206+
207+
### Plugins that need updating
202208

203209
- [Splunk](https://grafana.com/grafana/plugins/grafana-splunk-datasource)
204210

packaging/docker/build-enterprise.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if [ ${UBUNTU_BASE} = "0" ]; then
3131
DOCKERFILE="Dockerfile"
3232
else
3333
TAG_SUFFIX="-ubuntu"
34-
DOCKERFILE="Dockerfile.ubuntu"
34+
DOCKERFILE="ubuntu.Dockerfile"
3535
fi
3636

3737
echo "Building and deploying ${_docker_repo}:${_grafana_tag}${TAG_SUFFIX}"

packaging/docker/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ docker_build () {
6363
base_image="${base_arch}alpine:3.10"
6464
else
6565
libc=""
66-
dockerfile="Dockerfile.ubuntu"
66+
dockerfile="ubuntu.Dockerfile"
6767
base_image="${base_arch}ubuntu:18.10"
6868
fi
6969

packaging/docker/custom/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,31 @@ ARG GRAFANA_VERSION="latest"
22

33
FROM grafana/grafana:${GRAFANA_VERSION}
44

5+
USER root
6+
7+
ARG GF_INSTALL_IMAGE_RENDERER_PLUGIN="false"
8+
9+
RUN if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \
10+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
11+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
12+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
13+
apk --no-cache upgrade && \
14+
apk add --no-cache udev ttf-opensans chromium && \
15+
rm -rf /tmp/* && \
16+
rm -rf /usr/share/grafana/tools/phantomjs; \
17+
fi
18+
519
USER grafana
620

21+
ENV GF_RENDERER_PLUGIN_CHROME_BIN="/usr/bin/chromium-browser"
22+
23+
RUN if [ $GF_INSTALL_IMAGE_RENDERER_PLUGIN = "true" ]; then \
24+
grafana-cli \
25+
--pluginsDir "$GF_PATHS_PLUGINS" \
26+
--pluginUrl https://github.com/grafana/grafana-image-renderer/releases/latest/download/plugin-linux-x64-glibc-no-chromium.zip \
27+
plugins install grafana-image-renderer; \
28+
fi
29+
730
ARG GF_INSTALL_PLUGINS=""
831

932
RUN if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then \

0 commit comments

Comments
 (0)