Home > OS >  Grafana on Docker
Grafana on Docker

Time:04-11

I am using docker to run prometheus, grafana and node exporter. I am trying to use named volumes and I am having some issues with that. My docker-compose code is:

version: "3.7"
volumes:      
    grafana_ini:
    
    prometheus_data:
    
    grafana_data:
    
    dashboards_data:
    
services:
  grafana:
    build: ./grafana
    volumes:
            - grafana_ini:/etc/grafana/grafana.ini
            - grafana_data:/etc/grafana/provisioning/datasources/datasource.yml
            
            - dashboards_data:/etc/grafana/provisioning/dashboards
            - ./dashboards/linux_dashboard.json:/etc/grafana/provisioning/dashboards/linux_dashboard.json
    ports:
      - 3000:3000
    links:
            - prometheus
  prometheus:
    build: ./prometheus
    volumes:
            - prometheus_data:/etc/prometheus/prometheus.yml
    ports:
      - 9090:9090
  node-exporter:
    image: prom/node-exporter:latest
    container_name: node_exporter
    restart: unless-stopped
    expose:
      - 9100

and my dockerfile for grafana is:

FROM grafana/grafana:latest
COPY ./Ini/grafana.ini /etc/grafana/grafana.ini
COPY datasource.yml /etc/grafana/provisioning/datasources/datasource.yml
COPY ./dashboards/dashboard.yml /etc/grafana/provisioning/dashboards
COPY ./dashboards/server/linux_dashboard.json /etc/grafana/provisioning/dashboards
COPY ./dashboards/server/windows_dashboard.json /etc/grafana/provisioning/dashboards
EXPOSE 3000:3000

and I am getting this error while building it

ERROR: for 2022_grafana_1 Cannot create container for service grafana: source /var/lib/docker/overlay2/4ac5b487fd7fd52491b250c4afaa433801420cd907ac4a70ddb4589fdb99368b/merged/etc/grafana/grafana.ini is not directory

ERROR: for grafana Cannot create container for service grafana: source /var/lib/docker/overlay2/4ac5b487fd7fd52491b250c4afaa433801420cd907ac4a70ddb4589fdb99368b/merged/etc/grafana/grafana.ini is not directory

Can anybody please help me.

CodePudding user response:

It looks like there are some problems with the volume configuration in your Grafana container:

First, I think this was simply a typo in your question:

      - grafana_ini:/etc/grafana/grafana.inianticipated location in container

I suspect that you were actually intending this:

      - grafana_ini:/etc/grafana/grafana.ini

Which doesn't make any sense: grafana.ini is a file, but a volume is a directory. Docker won't allow you to mount a directory on top of a file, hence the error:

ERROR: .../etc/grafana/grafana.ini is not directory

You have the same problem with the grafana_data volume, which you're attempting to mount on top of datasource.yml:

      - grafana_data:/etc/grafana/provisioning/datasources/datasource.yml

I think you may be approaching this configuration in the wrong way; you may want to read through these documents:

It is possible to configure Grafana (and Prometheus!) using only bind mounts and environment variables (this includes installing plugin, data sources, and dashboards), so you don't need to build your own custom images.


Unrelated to this particular problem, there are some other things in your docker-compose.yml that are worth changing. You should no longer be using the links directive...

    links:
      - prometheus

...because Docker maintains DNS for you automatically; your containers can refer to each other by name with no additional configuration.

  • Related