Answers: <p>Check the volumes defined in the <code>Dockerfile</code> with the <code>VOLUME</code> instruction.</p>
  
  <p>If you don't want volume with random names to be automatically created, you can provide a host path to be bind-mounted to the volume, check the <code>-v</code> or <code>--mount</code> options, <a href="https://docs.docker.com/engine/admin/volumes/volumes/#choose-the--v-or-mount-flag" rel="nofollow noreferrer">https://docs.docker.com/engine/admin/volumes/volumes/#choose-the--v-or-mount-flag</a></p>
  
  <p>For example:</p>
  
  <pre><code>-v /srv/lib/grafana:/var/lib/grafana
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-01-01T01:53:58.097Z
Answers: 2018-01-01T01:53:58.097Z
Answers: Vincenzo Pii
Answers: <p>If anyone else is going down this rabbit hole.  Make sure you didn't accidentally define your volume with an <code>=</code> in your <code>Dockerfile</code></p>
  
  <p><strong>Wrong:</strong> </p>
  
  <pre><code>VOLUME = ["/logs", "/data"]
  </code></pre>
  
  <p><strong>Correct:</strong> </p>
  
  <pre><code>VOLUME ["/logs", "/data"]
  </code></pre>
  
  <p>It took me a long time to dig into why the anonymous volumes were being added by <code>docker-compose</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-04-21T20:12:27.147Z
Answers: 2020-04-21T20:12:27.147Z
Answers: Scott
Answers: <p>Research indicated that the <a href="https://docs.docker.com/engine/admin/volumes/" rel="noreferrer">anonymous volumes</a> were created by <code>influxdb</code> and <code>grafana/grafana</code>. </p>
  
  <blockquote>
    <p>Anonymous volumes are not given an explicit name when they are first
    mounted into a container, so Docker gives them a random name that is
    guaranteed to be unique within a given Docker host. Besides the name,
    named and anonymous volumes behave in the same ways.</p>
  </blockquote>
  
  <p><strong>Results</strong></p>
  
  <pre><code>version: "3"
  services:
    influxdb:
      image: influxdb:latest
      container_name: influxdb
      ports:
        - "8086:8086"
      #env_file:
      #  - 'env.influxdb'
      networks:
        - backend
      volumes:
        - influxdb-data:/var/lib/influxdb
  
    grafana:
      image: grafana/grafana:latest
      container_name: grafana
      ports:
        - "3000:3000"
      #env_file:
      #  - 'env.grafana'
      #  - 'secrets.grafana'
      networks:
        - backend
      volumes:
        - grafana-data:/var/lib/grafana
  
  networks:
    backend:
  
  volumes:
    influxdb-data:
    grafana-data:
  </code></pre>
  
  <p>results in:</p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               604a07040367512b09c618c6dcc71a7f55390c9c23de6ab08be7466414ed62da
  local               7f4b630073b31b6e772d3edef6da81b48643525edfc34281ea13fbd6b86ec270
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  </code></pre>
  
  <p>and everytime when <code>docker-compose down</code> and subsequenlty <code>up</code> is run the number of anonymous volumes doubles.</p>
  
  <p><em>What will happen if nginx will be pulled instead of influxdb and grafana?</em></p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  </code></pre>
  
  <p>and after <code>docker-compose down &amp;&amp; docker-compose up -d</code>?</p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  </code></pre>
  
  <p>It looks like that certain images created the additional anonymous volumes. Let's replace influxdb with nginx and use grafana.</p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               15b80416ab06abb629d9f634a0feff08f7c560f31d614b9b430855c16cdb75c7
  local               205a6f19cbf992c95b2e3be9f2fb1ca9ecec35fce550d0b7a4b9f32b0ef163b1
  local               474108f5b7b14fba92a3e5a980f3bf851388b2ee25d7417df5c42d9f176e084b
  local               5830a31a470ec8a42ddae7a37bb50487f3f36360318b2f9f5301b338507782b4
  local               9f00868a2fec0cfc0d34dc12d0879d39487a13128863722f400ad4c47df2d340
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  local               f47b1b7bbec8e50b32a7c39704c7c218165b284298d852313fa24bc7cbe6acc5
  </code></pre>
  
  <p>Everytime docker compose was run again, three anonymous volumes were created by the <code>grafana/grafana</code> docker image. Let's replace influxdb with nginx and revert the grafana to nginx:</p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  </code></pre>
  
  <p>and it remains two if restarted.</p>
  
  <p>It looks like that grafana is causing the issue.</p>
  
  <p><strong>Why are three new anonymous volumes created everytime grafana/grafana is restarted?</strong></p>
  
  <p><a href="https://github.com/grafana/grafana-docker/blob/master/Dockerfile#L16" rel="noreferrer">The grafana/grafana dockerfile</a> indicates that three anonymous volumes will be created:</p>
  
  <blockquote>
  <pre><code>VOLUME ["/var/lib/grafana", "/var/log/grafana", "/etc/grafana"]
  </code></pre>
  </blockquote>
  
  <p><a href="https://docs.docker.com/engine/reference/builder/#volume" rel="noreferrer">https://docs.docker.com/engine/reference/builder/#volume</a></p>
  
  <blockquote>
  <pre><code>FROM ubuntu
  RUN mkdir /myvol
  RUN echo "hello world" &gt; /myvol/greeting
  VOLUME /myvol
  </code></pre>
    
    <p>This Dockerfile results in an image that causes docker run, to create
    a new mount point at /myvol and copy the greeting file into the newly
    created volume.</p>
  </blockquote>
  
  <p><code>docker volume inspect &lt;volume name, e.g. 34cfafd4603dbc7e71a83e2520f978c8307b084143b3192de65a1995dc1d2f86&gt;</code> returned grafana data when the path that was returned was checked of two out of three anonymous volumes:</p>
  
  <pre><code>sudo ls /var/lib/docker/volumes/a0ecd00df8fc68ef36e777c7bf9ec5a496ee30e313b86889487501a53fa2e28e/_data
  grafana.ini  ldap.toml
  </code></pre>
  
  <p>and</p>
  
  <pre><code>sudo ls /var/lib/docker/volumes/34cfafd4603dbc7e71a83e2520f978c8307b084143b3192de65a1995dc1d2f86/_data
  grafana.db  plugins
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-10T10:00:08.527Z
Answers: `docker-compose down` is generally used when you're about to delete the project from your local machine. Or when you want to start with a clean slate. In these cases you might want to add `-v` to delete the volumes, and `--rmi=local` to delete the images that were built for the project. If you just want to restart: `docker-compose up -d` (if `docker-compose.yml` was changed), or `docker-compose up -d --force-recreate`. Also you can use `docker-compose stop` to stop the containers.
Answers: x-yuri
Answers: CC BY-SA 4.0
Answers: 2021-02-10T10:02:03.893Z
Answers: And yes, when you delete a container, the link to its anonymous volume is lost, so it's bound to create a new one when you create the container again. If you mount something into those directories (named volumes or bind-mounts), that won't happen. Also with named volumes you can see what project they belong to when you do `docker volume ls`.
Answers: x-yuri
Answers: CC BY-SA 3.0
Answers: 2017-12-29T01:07:19.197Z
Answers: 2017-12-29T01:28:35.470Z
Answers: 2017-12-29T01:28:35.470Z
Answers: 030
Body: <p>When starting a docker compose application, it creates named volume the first time around and then additional volumes each time it is started. Is this the normal behavior in that it creates incremental volumes or is my docker-compose file broken? In addition, after running <code>docker volume prune</code>, it removed two of the unnamed volumes</p>
  
  <p>This is the output after starting it twice:</p>
  
  <pre><code>DRIVER              VOLUME NAME
  local               2b33c81e6e955ff36061f4120b7181c7efc7aebded2f87eaa7290027f1e7a725
  local               74301eadc75018d6f7da76aec44bcf743e03261492cfcc33211941684a570030
  local               c42b1e2c17342c52b4b9e90f4d4b7fa24ccb30de5479e65cf4366e2373dfb0bf
  local               dcfa63dbf99362fc92fe3b981f50abebfe1bba03063d4dd9dd790f4c058817cf
  local               dockerinfluxdbgrafana_grafana-data
  local               dockerinfluxdbgrafana_influxdb-data
  </code></pre>
  
  <p>And for reference my docker-compose file</p>
  
  <pre><code>version: "3"
  services:
    influxdb:
      image: influxdb:latest
      container_name: influxdb
      ports:
        - "8086:8086"
      env_file:
        - 'env.influxdb'
      networks:
        - backend
      volumes:
        - influxdb-data:/var/lib/influxdb
  
    grafana:
      image: grafana/grafana:latest
      container_name: grafana
      ports:
        - "3000:3000"
      env_file:
        - 'env.grafana'
        - 'secrets.grafana'
      networks:
        - backend
      volumes:
        - grafana-data:/var/lib/grafana
  
  networks:
    backend:
  
  volumes:
    influxdb-data:
    grafana-data:
  </code></pre>
  
  <p><strong>Steps to reproduce</strong></p>
  
  <pre><code>docker-compose up -d &amp;&amp; docker-compose down &amp;&amp; docker-compose up -d &amp;&amp; docker-compose down &amp;&amp; docker-compose up -d &amp;&amp; docker-compose down
  </code></pre>
  
Comments: CC BY-SA 3.0
Comments: 2017-12-28T22:43:49.887Z
Comments: Please add a 'steps to reproduce' paragraph that indicates what commands and in what order these were issued.
Comments: 030
Comments: CC BY-SA 3.0
Comments: 2017-12-30T06:08:04.633Z
Comments: `docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down`
Comments: Moritz
Tags: <docker><docker-compose>
Title: Why are unnamed volumes created when `docker-compose up` is run and do these double after issuing `docker-compose down && docker-compose up`?
UserDisplayName: Moritz
ThreadText: # Why are unnamed volumes created when `docker-compose up` is run and do these double after issuing `docker-compose down && docker-compose up`?
  
  (Asked by: username_0 on 2017-12-27)
  
  When starting a docker compose application, it creates named volume the first time around and then additional volumes each time it is started. Is this the normal behavior in that it creates incremental volumes or is my docker-compose file broken? In addition, after running `docker volume prune`, it removed two of the unnamed volumes
  
  This is the output after starting it twice:
  
  ```
  DRIVER              VOLUME NAME
  local               2b33c81e6e955ff36061f4120b7181c7efc7aebded2f87eaa7290027f1e7a725
  local               74301eadc75018d6f7da76aec44bcf743e03261492cfcc33211941684a570030
  local               c42b1e2c17342c52b4b9e90f4d4b7fa24ccb30de5479e65cf4366e2373dfb0bf
  local               dcfa63dbf99362fc92fe3b981f50abebfe1bba03063d4dd9dd790f4c058817cf
  local               dockerinfluxdbgrafana_grafana-data
  local               dockerinfluxdbgrafana_influxdb-data
  
  ```
  
  And for reference my docker-compose file
  
  ```
  version: "3"
  services:
    influxdb:
      image: influxdb:latest
      container_name: influxdb
      ports:
        - "8086:8086"
      env_file:
        - 'env.influxdb'
      networks:
        - backend
      volumes:
        - influxdb-data:/var/lib/influxdb
  
    grafana:
      image: grafana/grafana:latest
      container_name: grafana
      ports:
        - "3000:3000"
      env_file:
        - 'env.grafana'
        - 'secrets.grafana'
      networks:
        - backend
      volumes:
        - grafana-data:/var/lib/grafana
  
  networks:
    backend:
  
  volumes:
    influxdb-data:
    grafana-data:
  
  ```
  
  **Steps to reproduce**
  
  ```
  docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down
  
  ```
  
  **Tags:** docker, docker-compose
  
  > **Comments:**
  > **username_1**: Please add a 'steps to reproduce' paragraph that indicates what commands and in what order these were issued.  
  > **username_0**: `docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down && docker-compose up -d && docker-compose down`  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2017-12-29. Score: 11 | Accepted answer
  
  Research indicated that the [anonymous volumes](https://docs.docker.com/engine/admin/volumes/) were created by `influxdb` and `grafana/grafana`.
  
  > Anonymous volumes are not given an explicit name when they are first
  > mounted into a container, so Docker gives them a random name that is
  > guaranteed to be unique within a given Docker host. Besides the name,
  > named and anonymous volumes behave in the same ways.
  
  **Results**
  
  ```
  version: "3"
  services:
    influxdb:
      image: influxdb:latest
      container_name: influxdb
      ports:
        - "8086:8086"
      #env_file:
      #  - 'env.influxdb'
      networks:
        - backend
      volumes:
        - influxdb-data:/var/lib/influxdb
  
    grafana:
      image: grafana/grafana:latest
      container_name: grafana
      ports:
        - "3000:3000"
      #env_file:
      #  - 'env.grafana'
      #  - 'secrets.grafana'
      networks:
        - backend
      volumes:
        - grafana-data:/var/lib/grafana
  
  networks:
    backend:
  
  volumes:
    influxdb-data:
    grafana-data:
  
  ```
  
  results in:
  
  ```
  DRIVER              VOLUME NAME
  local               604a07040367512b09c618c6dcc71a7f55390c9c23de6ab08be7466414ed62da
  local               7f4b630073b31b6e772d3edef6da81b48643525edfc34281ea13fbd6b86ec270
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  
  ```
  
  and everytime when `docker-compose down` and subsequenlty `up` is run the number of anonymous volumes doubles.
  
  *What will happen if nginx will be pulled instead of influxdb and grafana?*
  
  ```
  DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  
  ```
  
  and after `docker-compose down && docker-compose up -d`?
  
  ```
  DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  
  ```
  
  It looks like that certain images created the additional anonymous volumes. Let's replace influxdb with nginx and use grafana.
  
  ```
  DRIVER              VOLUME NAME
  local               15b80416ab06abb629d9f634a0feff08f7c560f31d614b9b430855c16cdb75c7
  local               205a6f19cbf992c95b2e3be9f2fb1ca9ecec35fce550d0b7a4b9f32b0ef163b1
  local               474108f5b7b14fba92a3e5a980f3bf851388b2ee25d7417df5c42d9f176e084b
  local               5830a31a470ec8a42ddae7a37bb50487f3f36360318b2f9f5301b338507782b4
  local               9f00868a2fec0cfc0d34dc12d0879d39487a13128863722f400ad4c47df2d340
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  local               f47b1b7bbec8e50b32a7c39704c7c218165b284298d852313fa24bc7cbe6acc5
  
  ```
  
  Everytime docker compose was run again, three anonymous volumes were created by the `grafana/grafana` docker image. Let's replace influxdb with nginx and revert the grafana to nginx:
  
  ```
  DRIVER              VOLUME NAME
  local               devopsstackexchange_grafana-data
  local               devopsstackexchange_influxdb-data
  
  ```
  
  and it remains two if restarted.
  
  It looks like that grafana is causing the issue.
  
  **Why are three new anonymous volumes created everytime grafana/grafana is restarted?**
  
  [The grafana/grafana dockerfile](https://github.com/grafana/grafana-docker/blob/master/Dockerfile#L16) indicates that three anonymous volumes will be created:
  
  > ```
  > VOLUME ["/var/lib/grafana", "/var/log/grafana", "/etc/grafana"]
  >
  > ```
  
  <https://docs.docker.com/engine/reference/builder/#volume>
  
  > ```
  > FROM ubuntu
  > RUN mkdir /myvol
  > RUN echo "hello world" > /myvol/greeting
  > VOLUME /myvol
  >
  > ```
  >
  > This Dockerfile results in an image that causes docker run, to create
  > a new mount point at /myvol and copy the greeting file into the newly
  > created volume.
  
  `docker volume inspect <volume name, e.g. 34cfafd4603dbc7e71a83e2520f978c8307b084143b3192de65a1995dc1d2f86>` returned grafana data when the path that was returned was checked of two out of three anonymous volumes:
  
  ```
  sudo ls /var/lib/docker/volumes/a0ecd00df8fc68ef36e777c7bf9ec5a496ee30e313b86889487501a53fa2e28e/_data
  grafana.ini  ldap.toml
  
  ```
  
  and
  
  ```
  sudo ls /var/lib/docker/volumes/34cfafd4603dbc7e71a83e2520f978c8307b084143b3192de65a1995dc1d2f86/_data
  grafana.db  plugins
  
  ```
  
  > **Comments:**
  > **username_4**: `docker-compose down` is generally used when you're about to delete the project from your local machine. Or when you want to start with a clean slate. In these cases you might want to add `-v` to delete the volumes, and `--rmi=local` to delete the images that were built for the project. If you just want to restart: `docker-compose up -d` (if `docker-compose.yml` was changed), or `docker-compose up -d --force-recreate`. Also you can use `docker-compose stop` to stop the containers.  
  > **username_4**: And yes, when you delete a container, the link to its anonymous volume is lost, so it's bound to create a new one when you create the container again. If you mount something into those directories (named volumes or bind-mounts), that won't happen. Also with named volumes you can see what project they belong to when you do `docker volume ls`.  
  
  ---
  
  ### Answer by username_2 on 2018-01-01. Score: 3
  
  Check the volumes defined in the `Dockerfile` with the `VOLUME` instruction.
  
  If you don't want volume with random names to be automatically created, you can provide a host path to be bind-mounted to the volume, check the `-v` or `--mount` options, <https://docs.docker.com/engine/admin/volumes/volumes/#choose-the--v-or-mount-flag>
  
  For example:
  
  ```
  -v /srv/lib/grafana:/var/lib/grafana
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2020-04-21. Score: 1
  
  If anyone else is going down this rabbit hole. Make sure you didn't accidentally define your volume with an `=` in your `Dockerfile`
  
  **Wrong:**
  
  ```
  VOLUME = ["/logs", "/data"]
  
  ```
  
  **Correct:**
  
  ```
  VOLUME ["/logs", "/data"]
  
  ```
  
  It took me a long time to dig into why the anonymous volumes were being added by `docker-compose`
  
  
  ---
  
  