如何删除 Postgres docker 卷?
我有一个 docker-compose.yml,用于使用 docker context 从本地(Mac)计算机部署到远程主机。 compose配置如下:
database:
image: postgres:14.2
restart: on-failure
volumes:
- ./db-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
为了持久化数据,我定义了一个卷./db-data:/var/lib/postgresql/data
。我的本地计算机中不存在此 db-data
文件夹。我想完全删除此安装,因为我不需要任何以前保留的数据。我知道我可以定义一个新的卷目录,但我想使用相同的目录名称(db-data
)。我已尝试以下操作:
- docker compose down --volume --remove-orphans - 当我重新创建新容器时,以前保留的数据仍然存在
- 没有名为 ./db-data 的文件夹/code> 在我的 Mac 工作目录中。
- 我尝试在我的 Mac 中搜索 var/lib/docker 。但该目录不存在。
- Docker for Mac 应用程序未列出任何卷
- 部署数据库的远程主机中没有
db-data
I have a docker-compose.yml
which I am using to deploy to a remote host from my local (Mac) machine using docker context
. The compose config is as follows:
database:
image: postgres:14.2
restart: on-failure
volumes:
- ./db-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
In order to persist data, I have defined a volume ./db-data:/var/lib/postgresql/data
. This db-data
folder does not exist in my local machine. I want delete this mount completely because I don't want any of the previously persisted data. I know I can define a new volume directory but I would like to use the same directory name (db-data
). I have tried the following:
docker compose down --volume --remove-orphans
- when I recreate new container, previously persisted data still exists- There is no folder called
./db-data
in my Mac working directory. - I tried searching
var/lib/docker
in my Mac. But that directory does not exists. - Docker for Mac app doesn't list any volumes
- There is no
db-data
in the remote host where the database is deployed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行 dockerspect列出了容器的挂载目录。挂载目录类似于我本地计算机的绝对路径。例如,它类似于
/Users//dir/db-data
。当我看到这个时,由于前缀Users/
,我认为它必须位于本地计算机中,但实际上该路径是在远程计算机的根目录中找到的。Running
docker inspect <container-id>
listed the mount directory for the container. The mount directory resembled absolute path of my local computer. For example it was like/Users/<user-name>/dir/db-data
. When I saw this I assumed this had to be in the local computer due to the prefixUsers/<user-name>
but this path was actually found in the root of the remote machine.那是因为 docker 卷的目录位于 MACOS 的 docker vm 中。
Mac/OS X 上的 /var/lib/docker 在哪里< /a>
您必须按照此操作才能看到音量
Thats because the directory for docker volumes is in the docker vm for MACOS.
Where is /var/lib/docker on Mac/OS X
You would have to follow this to see the volume