postgresqldockerdocker-composevolumesdocker-named-volume

Remove a named volume with docker-compose?


If I have a docker-compose file like:

version: "3"
services:
  postgres:
    image: postgres:9.4
    volumes:
      - db-data:/var/lib/db
volumes:
  db-data:

... then doing docker-compose up creates a named volume for db-data. Is there a way to remove this volume via docker-compose? If it were an anonymous volume, then docker-compose rm -v postgres would do the trick. But as it stands, I don't know how to remove the db-data volume without reverting to docker commands. It feels like this should be possible from within the docker-compose CLI. Am I missing something?


Solution

  • docker-compose down -v
    

    removes all volumes attached. See the docs