1

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.

1
  • You mounted the volume on your OS filesystem in ./postgres. You can delete that folder. Or you can remove the volume with docker volume rm volume_name Commented Jan 21, 2022 at 22:08

2 Answers 2

3

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/

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

When I say subdirectory, I want to say "subdirectory of the directory where the docker-compose file is"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.