Persistent volume for user accounts - Docker

Dears,

Is it possible to map an external volume to the container? For when you need to restart the container or other such activity, the user account settings remain valid.

I was able to map the plugins volume:

- ./var/lib/grafana/plugins:/var/lib/grafana/plugins

I’ve tried mapping so that user account data is persisted. But I did not succeed.


This my docker-compose.yml

version: ‘2’

services:

monitor:
restart: always
image: semantix/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=password
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource,foursquare-clouderamanager-datasource
volumes:
- ./var/lib/grafana/plugins:/var/lib/grafana/plugins
- .:/home
networks:
- connection
ports:
- 3000:3000

networks:
connection:

You are using (private) semantix/grafana Docker image, so only maintainer of this image knows the exact structure of the image. If it is based on official Grafana Docker image, then check official doc: http://docs.grafana.org/installation/docker/#grafana-container-with-persistent-storage-recommended

Thanks for the answer.

Yes, the image that is pointed in the docker-compose is a local image. But it was generated from a Dockerfile:

If anyone can help, I will be very grateful.


Dockerfile:

FROM debian:stretch-slim

ARG GRAFANA_URL=“https://s3-us-west-2.amazonaws.com/grafana-releases/master/grafana-latest.linux-x64.tar.gz
ARG GF_UID=“472”
ARG GF_GID=“472”

ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
GF_PATHS_CONFIG="/etc/grafana/grafana.ini"
GF_PATHS_DATA="/var/lib/grafana"
GF_PATHS_HOME="/usr/share/grafana"
GF_PATHS_LOGS="/var/log/grafana"
GF_PATHS_PLUGINS="/var/lib/grafana/plugins"
GF_PATHS_PROVISIONING="/etc/grafana/provisioning"

RUN apt-get update && apt-get install -qq -y tar libfontconfig curl ca-certificates &&
mkdir -p “$GF_PATHS_HOME/.aws” &&
curl “$GRAFANA_URL” | tar xfvz - --strip-components=1 -C “$GF_PATHS_HOME” &&
apt-get autoremove -y &&
rm -rf /var/lib/apt/lists/* &&
groupadd -r -g $GF_GID grafana &&
useradd -r -u $GF_UID -g grafana grafana &&
mkdir -p “$GF_PATHS_PROVISIONING/datasources”
“$GF_PATHS_PROVISIONING/dashboards”
“$GF_PATHS_LOGS”
“$GF_PATHS_PLUGINS”
“$GF_PATHS_DATA” &&
cp “$GF_PATHS_HOME/conf/sample.ini” “$GF_PATHS_CONFIG” &&
cp “$GF_PATHS_HOME/conf/ldap.toml” /etc/grafana/ldap.toml &&
chown -R grafana:grafana “$GF_PATHS_DATA” “$GF_PATHS_HOME/.aws” “$GF_PATHS_LOGS” “$GF_PATHS_PLUGINS” &&
chmod 777 “$GF_PATHS_DATA” “$GF_PATHS_HOME/.aws” “$GF_PATHS_LOGS” “$GF_PATHS_PLUGINS”

EXPOSE 3000

COPY ./run.sh /run.sh

USER grafana
WORKDIR /
ENTRYPOINT [ “/run.sh” ]

It is mentioned in the doc: http://docs.grafana.org/installation/docker/#grafana-container-using-bind-mounts :

--volume "$PWD/data:/var/lib/grafana"

So use:

volumes:
- ./var/lib/grafana/:/var/lib/grafana

I recommend to read full doc - there is an important info about write permissions.