添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I’m new to docker and containers, I have this docker-compose.yml that configure my stack.
The issue that I’m facing is that InfluxDB it’s not persiting data into ‘/var/lib/influxdb’ in case of a restart/power outage.
Once the container get up and running again, all the data is gone, and I have to create the buckets and the credentials for admin user again.
The other 3 containers on the stack persist data on the same scenario.
Can you advise me on what could be wrong with this .yml file about influxDB configuration?
How do I solve this and get influxDB to persist data?
also, is there a way to save influxDB logs to a volume?

version: '3'
services:
  emqx:
    image: emqx/emqx
    container_name: emqx
    networks:
      ming_network:
        ipv4_address: 172.20.0.2
    ports:
      - "1883:1883"
      - "8083:8083"
      - "8883:8883"
      - "18083:18083"
    environment:
      - EMQX_NAME=mybroker
    restart: always
    volumes:
      - emqx_data:/opt/emqx/data
      - emqx_log:/opt/emqx/log
      - emqx_etc:/opt/emqx/etc
  influxdb:
    image: influxdb:latest
    container_name: influxdb
    networks:
      ming_network:
        ipv4_address: 172.20.0.3
    ports:
      - "8086:8086"
    restart: always
    volumes:
      - influxdb_data:/var/lib/influxdb
  nodered:
    image: nodered/node-red
    container_name: nodered
    networks:
      ming_network:
        ipv4_address: 172.20.0.4
    ports:
      - "1880:1880"
    restart: always
    volumes:
      - nodered_data:/data
  grafana:
    image: grafana/grafana
    container_name: grafana
    networks:
      ming_network:
        ipv4_address: 172.20.0.5
    ports:
      - "3000:3000"
    restart: always
    volumes:
      - grafana_data:/var/lib/grafana
networks:
  ming_network:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.20.0.0/16
volumes:
  emqx_data:
  emqx_log:
  emqx_etc:
  influxdb_data:
  nodered_data:
  grafana_data:

Thanks.

From what you’ve shared, it looks like the InfluxDB service is using a volume mapped to /var/lib/influxdb inside the container. This should be the correct location for data persistence for InfluxDB.

Let’s address the problems one by one:

  • InfluxDB Data Persistence:
  • Ensure the volume influxdb_data is created and there’s no error during its creation.
  • Make sure you’re not inadvertently deleting the influxdb_data volume. Ensure that you’re not running docker-compose down -v or any other command that might destroy the volume.
  • If you’re running an InfluxDB version that’s 2.x or newer, the data is stored in /var/lib/influxdb2. If you’re using this version, modify your volume mapping like this:
  • yamlCopy code

    volumes:
      - influxdb_data:/var/lib/influxdb2
    
  • Saving InfluxDB Logs to a Volume:
  • InfluxDB logs are, by default, sent to stdout and can be viewed with docker logs <container_name>. But if you want to store them inside a volume, you’d typically have to modify the InfluxDB configuration to send logs to a file and then map that file or directory to a volume. This isn’t directly supported by the standard InfluxDB Docker image without customization.
  • If you just want to persist the logs outside the container, consider redirecting the logs from docker logs to a file on the host system.
  • General Suggestions:
  • Check the logs: Inspect the InfluxDB container logs with docker logs influxdb. This might provide hints if there’s any issue with the database initialization or any other problems.
  • Data Safety: Before making any changes, especially if you’ve important data, ensure you have backups.
  • Version Pinning: It’s generally a good practice to pin your images to specific versions rather than using latest. This ensures that you’re using a known, stable version, and it prevents unexpected behavior when the image is updated upstream.
  • In summary, the primary issue may lie in using the wrong directory for InfluxDB 2.x. If that’s the version you’re using, make sure you map to /var/lib/influxdb2. Always check the documentation for the specific version of the software you’re using to ensure you have the right paths and configurations.

    Hi Anaisdg,

    After replacing the data path to /var/lib/influxdb2 the issue was solved after restarting the container.
    thnaks.