在Docker Desktop(Windows)中查找数据卷 [英] Locating data volumes in Docker Desktop (Windows)

查看:875
本文介绍了在Docker Desktop(Windows)中查找数据卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我正在尝试学习docker,但对于数据量实际存在的位置感到困惑.

I'm trying to learn docker at the moment and I'm getting confused about where data volumes actually exist.

我正在使用适用于Windows的Docker桌面. (Windows 10)

I'm using Docker Desktop for Windows. (Windows 10)

在文档中,他们说在对象上运行docker inspect将为您提供源: https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume

In the docs they say that running docker inspect on the object will give you the source:https://docs.docker.com/engine/tutorials/dockervolumes/#locating-a-volume

$ docker inspect web

"Mounts": [
    {
        "Name": "fac362...80535",
        "Source": "/var/lib/docker/volumes/fac362...80535/_data",
        "Destination": "/webapp",
        "Driver": "local",
        "Mode": "",
        "RW": true,
        "Propagation": ""
    }
]

但是我没看到这个,我得到了以下信息:

however I don't see this, I get the following:

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

有人可以帮助我吗?我只想知道我的数据量实际上在哪里,它在我的主机上吗?如果是这样,我如何获得它的路径?

Can anyone help me? I just want to know where my data volume actually exists is it on my host machine? If so how can i get the path to it?

推荐答案

您的卷目录为/var/lib/docker/volumes/blog_postgres-data/_data,而/var/lib/docker通常挂载在C:\Users\Public\Documents\Hyper-V\Virtual hard disks中.无论如何,您可以通过查看Docker设置来进行检查.

Your volume directory is /var/lib/docker/volumes/blog_postgres-data/_data, and /var/lib/docker usually mounted in C:\Users\Public\Documents\Hyper-V\Virtual hard disks. Anyway you can check it out by looking in Docker settings.

您可以参考这些文档以获取有关如何在Windows上与Docker共享驱动器.

You can refer to these docs for info on how to share drives with Docker on Windows.

BTW,Source是主机上的位置,Destination是容器内在以下输出中的位置:

BTW, Source is the location on the host and Destination is the location inside the container in the following output:

"Mounts": [
{
    "Name": "fac362...80535",
    "Source": "/var/lib/docker/volumes/fac362...80535/_data",
    "Destination": "/webapp",
    "Driver": "local",
    "Mode": "",
    "RW": true,
    "Propagation": ""
}
]

================================================ ==========================

===========================================================================

已更新,可以回答评论中的问题:

Updated to answer questions in the comment:

我的主要好奇是共享图像等很棒,但是我如何共享数据?

My main curiosity here is that sharing images etc is great but how do I share my data?

实际上volume是为此目的而设计的(在Docker容器中管理数据).卷中的数据保留在主机FS上,并与Docker容器/映像的生命周期隔离.您可以通过以下方式在一个卷中共享数据:

Actually volume is designed for this purpose (manage data in Docker container). The data in a volume is persisted on the host FS and isolated from the life-cycle of a Docker container/image. You can share your data in a volume by:

  • 安装Docker卷以托管和重用它

  • Mount Docker volume to host and reuse it

docker run -v /path/on/host:/path/inside/container image

然后,您的所有数据将保留在/path/on/host中;您可以备份它,将其复制到另一台计算机上,然后以相同的体积重新运行容器.

Then all your data will persist in /path/on/host; you could back it up, copy it to another machine, and re-run your container with the same volume.

创建并安装数据容器.

创建数据容器:docker create -v /dbdata --name dbstore training/postgres /bin/true

使用--volumes-from:docker run -d --volumes-from dbstore --name db1 training/postgres在此容器上运行其他容器,然后db1生成的所有数据将保留在容器dbstore的容量中.

Run other containers based on this container using --volumes-from: docker run -d --volumes-from dbstore --name db1 training/postgres, then all data generated by db1 will persist in the volume of container dbstore.

有关更多信息,您可以参考官方Docker卷文档.

For more information you could refer to the official Docker volumes docs.

简单来说,volumes只是主机上包含所有容器数据的目录,因此您可以使用以前使用的任何方法来备份/共享数据.

Simply speaking, volumes is just a directory on your host with all your container data, so you could use any method you used before to backup/share your data.

我可以像处理图像一样将卷推到docker-hub吗?

can I push a volume to docker-hub like I do with images?

不.您可以将Docker image 推送到Docker集线器(又称注册表");但是数据不是.您可以使用任何喜欢的方法来备份/持久保存/共享数据,但是将数据推送到Docker注册表以共享它没有任何意义.

No. A Docker image is something you can push to a Docker hub (a.k.a. 'registry'); but data is not. You could backup/persist/share your data with any method you like, but pushing data to a Docker registry to share it does not make any sense.

我可以进行备份等吗?

can I make backups etc?

是的,如上所述:-)

这篇关于在Docker Desktop(Windows)中查找数据卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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