我创建了一个卷
localhost:localport
现在我在我的 docker-compose.xml 中使用它
docker volume create postgresql_db
有时我想停止并清理 docker 系统。
所以我试着跑
services:
postgresql:
image: "postgres:11-alpine"
volumes:
- type: volume
source: postgresql_data
target: /var/lib/postgresql/data
volume:
nocopy: true
environment:
PGDATA: '/var/lib/postgresql/data/pgdata'
networks: # connect to the bridge
- postgresql_network
command: ["postgres", "-c", "log_statement=all","-c", "log_destination=stderr"]
volumes:
postgresql_data:
external: true
这也会删除 docker stop $(docker ps -aq) # stop all containers
docker rm $(docker ps -a -q) # remove all containers
docker container prune
docker image prune
docker network prune
docker volume prune #<-- remove all dangling volumes also
即 postgresql_data
如何避免这种情况。
答案 0 :(得分:0)
好吧,根据 Docker's documentation,您可以简单地过滤您的卷(例如按标签):
docker volume prune --filter label!=postgresql_db
然后所有not(查看!
)名为postgresql_db且未附加到1个或多个容器的卷将被删除。>