Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Postgres Clear all Data

I'm running postgress inside a docker container. I'm trying to completely remove it and re-install.

Everytime I start it seems to be 'restarting' rather than making a fresh instance.

When I re-start the new instance I get a message like this telling me when I last shut down the previous database:

postgres            | LOG:  database system was shut down at 2017-04-25 18:28:02 UTC 

These are the steps I took in an attempt to completely remove the database.

  docker kill $(docker ps -q) # stop all containers   docker rm $(docker ps -a -q) # remove all containers    docker rmi $(docker images -q) # remove all images   docker network prune # remove all networks   docker volume prune # remove all volumes  

Yet I always get the log indicating when the previous database was shutdown. How can I completely remove all traces of the database?

like image 704
Philip Kirkbride Avatar asked Apr 25 '17 18:04

Philip Kirkbride


2 Answers

For docker-compose the correct way to remove volumes would be docker-compose down --volumes or docker-compose down --rmi all --volumes.

For more information see https://docs.docker.com/compose/reference/down/.

like image 156
Pieter Venter Avatar answered Sep 20 '22 08:09

Pieter Venter


You can try:

docker volume rm $(docker volume ls -q) 

Otherwise, the proper way to do it would be to do:

docker rm -f -v postgres_container_name 

However, I don't think the volumes are the issue. When you do a docker run --rm -it postgres the entrypoint loads some configuration and restarts the database, so it is expected to see that message.

like image 25
creack Avatar answered Sep 20 '22 08:09

creack