问题描述
当我看到这个示例撰写文件时,我正在为培训设置一些材料:
I was setting up some materials for a trainning, when I came around this sample compose file:
https://github.com/dockersamples/示例投票应用程序/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 卷位于何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!