I would like to delete my postgres volume and start over (learning the process). When I enter the postgres container using docker exec -it [container_id] sh
I can see the postgres files like this: ls var/lib/postgresql/data/
.
When I try to delete these files using rm -r var/lib/postgresql/
I get:
rm: can’t remove ‘var/lib/postgresql/data’: Resource busy
If I stop this container, I will not be able to delete the volume. How can I delete it?
Fwiw my docker-compose looks as such:
services:
db:
container_name: postgres
image: postgres:13-alpine
volumes:
- ./postgres:/var/lib/postgresql/data
env_file:
- .env
Edit:
The docker-compose is pulled from my GitHub. I am not sure where any of the files are on the server. NVM, found them. Thanks.
2
Answers
The contents you can access from inside the container at /var/lib/postgresql/data, are the contents of the subdirectory postgres in the host machine, so you could add or remove files from the host machine
You mounted
./postgres
from your host system at ยด/var/lib/postgresql/data` in your docker container:So just navigate to
./postgres
on your host system and delete the content.You even can use Finder/Explorer to do this.
See also: https://docs.docker.com/storage/bind-mounts/