Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete Postgres files in Docker container

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

You mounted ./postgres from your host system at ´/var/lib/postgresql/data` in your docker container:

volumes:
      - ./postgres:/var/lib/postgresql/data

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/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading