Docker:此撰写文件的Docker卷位于何处 [英] Docker: where is docker volume located for this compose file

查看:102
本文介绍了Docker:此撰写文件的Docker卷位于何处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我处理此示例撰写文件时,我正在设置一些培训材料:

I was setting up some materials for a trainning, when I came around this sample compose file:

https://github.com/dockersamples/example-voting-app/blob/master/docker-compose.yml

,但在文件的第48和49行上我找不到该卷的安装方式:

and I couldn't find out how this volume is mounted, on lines 48 and 49 of the file:

volumes:
  db-data:

有人可以向我解释主机上的该卷在哪里吗?找不到容器后,我也不想保留任何postgresql数据。网络发生了类似的事情:

Can someone explain me where is this volume on the host? Couldn't find it and I wouldn't like to keep any postgresql data dangling around after the containers are gone. Similar thing happens to the networks:

networks:
  front-tier:
  back-tier:

为什么docker compose接受像这样的空网络定义?

Why docker compose accepts empty network definitions like this?

推荐答案

查找卷



类似这样的卷在Docker内部,并存储在Docker存储区中(通常位于 / var / lib / docker )。您可以获得卷的列表:

Finding the volumes

Volumes like this are internal to Docker and stored in the Docker store (which is usually all under /var/lib/docker). You can get a list of volumes:

$ docker volume ls
DRIVER              VOLUME NAME
local               1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465
local               2f13b0cec834a0250845b9dcb2bce548f7c7f35ed9cdaa7d5990bf896e952d02
local               a3d54ec4582c3c7ad5a6172e1d4eed38cfb3e7d97df6d524a3edd544dc455917
local               e6c389d80768356cdefd6c04f6b384057e9fe2835d6e1d3792691b887d767724

如果要执行以下操作,您可以找到卷的确切存储位置:

You can find out exactly where the volume is stored on your system if you want to:

$ docker inspect 1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465
[
    {
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465/_data",
        "Name": "1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465",
        "Options": {},
        "Scope": "local"
    }
]



清理未使用的卷



只要确保不晃晃,就可以使用修剪命令,在这种情况下为 docker volume prune 。这将为您提供此输出,您可以选择是否继续修剪。

Cleaning up unused volumes

As far as just ensuring that things are not left dangling, you can use the prune commands, in this case docker volume prune. That will give you this output, and you choose whether to continue pruning or not.

$ docker volume prune
WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N]



docker-compose.yml中的空定义



当您不需要定义卷或网络应该存在的其他事情时,就倾向于接受诸如卷和网络之类的这些空定义。也就是说,如果您要创建它,但可以使用默认设置,则没有特别的理由指定参数。

"Empty" definitions in docker-compose.yml

There is a tendency to accept these "empty" definitions for things like volumes and networks when you don't need to do anything other than define that a volume or network should exist. That is, if you want to create it, but are okay with the default settings, then there is no particular reason to specify the parameters.

这篇关于Docker:此撰写文件的Docker卷位于何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆