1

Problem

I believe Docker Compose should be able to remove all volumes it creates because it seems easier and safer to do so. However, locally bind-mounted volumes on the host machine created by Docker Compose cannot be removed by Docker Compose, so I have to remove them manually when necessary.

I want to know if there is a way to remove the bind-mounted volumes on the host machine from within Docker Compose. From my research, this seems to be the only issue regarding this matter.

Example

The command below does not delete the locally bind-mounted volume created by Docker Compose:

docker compose down --rmi all --volumes

In other words, the data folder owned by Docker is not removed, as shown below:

drwx------ 19 999 docker 4096 Jul 19 17:58 data

Therefore, I need to follow these steps to remove it.

sudo chown -R <owner>:<group> data
rm -rf data

Here is the Docker Compose setup for your reference:

docker-compose.yaml
services:
  postgres:
    image: postgres
    env_file:
      - postgres.env
    volumes:
      - postgres_bind_volume:/var/lib/postgresql/data
    ports:
      - 5432:5432

volumes: postgres_bind_volume: driver: local driver_opts: type: none o: bind device: ./data

0 Answers0