Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

database lost on docker restart

I'm running influxdb and grafana on Docker with Windows 10.

Every time I shut down Docker, I lose my database.

Here's what I know:

  • I have tried adjusting the retention policies, with no effect on the outcome
  • I can shut down and restart the containers (docker-compose down) and the database is still there. Only when I shut down Docker for Windows do I lose the database.
  • I don't see any new folders on the mapped directory when I create a new database (/data/influxdb/data/)'. Only the '_internal' folder persists, which I assume corresponds to the persisting database called '_internal'

Here's my yml file. Any help greatly appreciated.

version: '3'

services:
  # Define an InfluxDB service
  influxdb:
    image: influxdb
    volumes:
      - ./data/influxdb:/var/lib/influxdb
    ports:
      - "8086:8086"
      - "80:80"
      - "8083:8083"
  grafana:
    image: grafana/grafana
    volumes:
      - ./data/grafana:/var/lib/grafana
    container_name: grafana
    ports:
      - "3000:3000"
    env_file:
      - 'env.grafana'
    links:
      - influxdb
  # Define a service for using the influx CLI tool.
  # docker-compose run influxdb-cli
  influxdb-cli:
    image: influxdb
    entrypoint:
      - influx
      - -host
      - influxdb
    links:
      - influxdb
like image 442
C Jones Avatar asked Dec 14 '22 18:12

C Jones


1 Answers

If you are using docker-compose down/up, keep in mind that this is not a "restart" because:

  • docker-compose up creates new containers and
  • docker-compose down removes them :

docker-compose up

Builds, (re)creates, starts, and attaches to containers for a service.

docker-compose down

Stops containers and removes containers, networks, volumes, and images created by up.

So, removing the containers + not using a mechanism to persist data (such as volumes) means that you lose your data ☹️

On the other hand, if you keep using:

  • docker-compose start
  • docker-compose stop
  • docker-compose restart

you deal with the same containers, the ones created when you ran docker-compose up.

like image 182
tgogos Avatar answered Dec 25 '22 22:12

tgogos