Unknown volumes created when using Docker Compose

Hello community,

when using the following docker compose file (being executed with “docker compose -d”)

version: '3.7'
name: test

services:

  telegraf:
    image: telegraf
    container_name: telegraf
    privileged: true
    user: telegraf:1000
    # "1000" is the group id of the docker daemon, run: $(stat -c '%g' /var/run/docker.sock)
    # In case of error: sudo chmod 666 /var/run/docker.sock
    volumes:
    - /opt/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
    - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - influxdb
    #links:
    #  - influxdb
    network_mode: "host"
    ports:
    - '127.0.0.1:8125:8125/udp'

  influxdb:
    image: influxdb:2.4.0
    container_name: influxdb
    env_file: .env
    environment:
      - INFLUXDB_INIT_MODE:$INFLUXDB_INIT_MODE
      - INFLUXDB_INIT_USERNAME:$INFLUXDB_INIT_USERNAME
      - INFLUXDB_INIT_PASSWORD:$INFLUXDB_INIT_PASSWORD
      - INFLUXDB_INIT_ORG:$INFLUXDB_INIT_ORG
      - INFLUXDB_INIT_BUCKET:$INFLUXDB_INIT_BUCKET
      - INFLUXDB_INIT_ADMIN_TOKEN:$INFLUXDB_INIT_ADMIN_TOKEN
      #- INFLUXD_LOG_LEVEL:$INFLUXD_LOG_LEVEL
      - TZ:$TZ
    labels:
        com.centurylinklabs.watchtower.enable: "true"
    network_mode: "host"
    ports:
      - '127.0.0.1:8086:8086'
    volumes:
      - influxdb_data:/imports:/imports
      - influxdb_data:/influxdb_data:/var/lib/influxdb
      - influxdb_data:/influxdb_data2:/var/lib/docker/volumes
      - influxdb_data:/etc/influxdb_data:/etc/influxdb2

  grafana:
    image: grafana/grafana-oss:latest
    container_name: grafana
    depends_on:
      - influxdb
    env_file: .env
    network_mode: "host"
    #links:
    #  - influxdb
    environment:
      - GF_SECURITY_ADMIN_USER=$GF_SECURITY_ADMIN_USER
      - GF_SECURITY_ADMIN_PASSWORD=$GF_SECURITY_ADMIN_PASSWORD

    ports:
      - '127.0.0.1:3000:3000'
    volumes:
      - grafana_data:/var/lib/grafana
      - grafana_data:/etc/grafana/provisioning/
      - grafana_data:/var/lib/grafana/dashboards/

volumes:
  grafana_data: 
  influxdb_data:

There are always two additional volumes created…

  • /var/lib/docker/volumes/7a2c464a67ca741fac52cd81a1b90b5fed2af52168da7830fad8333a71c4c99f/_data
    → Containers using volume:
    → Container Name: influxdb <-> mounted at: /var/lib/influxdb2

  • /var/lib/docker/volumes/b560e46e2ffa9cec7f73ee570cfc9dee5065a28345eb8d0db90bcc97eda2566a/_data
    → Containers using volume:
    → Container Name: influxdb <-> mounted at: /etc/influxdb2

How can I add these volumes to “influxdb_data”?

What is this supposed to mean? Just out of curiosity: do you think your mapped subfolders within the named volume into container paths? This is not how it works, volumes do not allow to map subfolders into container folders.

Furthermore, anonymous volumes are created, when no volume is mapped against a container path that was declared as VOLUME in the Dockerfile used to create the images.

Generally the way you use volumes doesn’t look right. You need to use one volume per container target path. Not one volume for several container target paths.

1 Like

Your assumption is right. My intention was to have 2 volumes active after docker compose:

  • one for InfluxDB and
  • one for Grafana

covering all the folders which will be created for these two services.

Regarding the latest InfluxDB image ( Image Layer Details - influxdb:latest | Docker Hub), the mentioned anonymous volumes are listed in line 13 (

13 VOLUME [/var/lib/influxdb2 /etc/influxdb2] 0 B

)

Just to have one correct example, what would be the needed steps in order to have the InfluxDB stuff stored in InfluxDB_Data volume and the Grafana stuff stored in Grafana_Data volume?

OR do you mean with “one volume per container target path” that I need a volume having the “InfluxDB AND Grafana” stuff stored in one volume? Resp. where do I “add” the two folders (see above) to a volume? Does this mean that I have then 4 volumes for running these two services?

This is not how it works. To phrase it in your words: each volume covers one folder (and it’s subfolders).

For instance your influxdb2 container will need at least two volumes: one for /var/lib/influxdb2 and one for /etc/influxdb2.

    volumes:
      - influxdb_config:/etc/influxdb2
      - influxdb_data:/var/lib/influxdb2
    ...
volumes:
  influxdb_config: {}
  influxdb_data: {}

Though, if you run docker on a single node, you can also use bind volumes, where a host folder is bind mounted into a container folder.

Assumed you create your folders like this: sudo mkdir -p /opt/container_data/influxdb/{config,data}, then the volume mapping would look like this:

    volumes:
      - /opt/container_data/influxdb/config/:/etc/influxdb2
      - /opt/container_data/influxdb/data:/var/lib/influxdb2

Of course with a bind, you need to take care that the owner of the host folder aligns with the UID:GID that executes the process inside the container to prevent permission issues.

1 Like

Thanks again for your extended reply. As I have no swarm/cluster but only single nodes running, I will go the way you proposed.