'Differences between external and default volume in Docker Compose?

There are different custom installations of a variety of docker-compose applications. And often they use external volumes instead of the default ones directly in the compose file.

Here's an example of creation by install script (runs first): https://github.com/getsentry/onpremise/blob/master/install/create-docker-volumes.sh

And later this volume is used: https://github.com/getsentry/onpremise/blob/master/docker-compose.yml#L361

volumes:
  sentry-data:
    external: true
  sentry-postgres:
    external: true

Can anyone explain what is the point? Why just not compose volumes?

volumes:
  sentry-data:


Solution 1:[1]

External volumes must be created and removed by a docker volumes command. docker-compose up will not automatically create external volumes, and docker-compose down -v will not remove them.

Also external volumes can be mapped into multiple projects.

I use external volumes when I want extra control over their creation and removal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TerryE