在 Docker 桌面 (Windows) 中定位数据卷 [英] Locating data volumes in Docker Desktop (Windows)

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

问题描述

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

我正在使用 Windows 版 Docker 桌面.(Windows 10)

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

$ docker 检查网络坐骑":[{"名称": "fac362...80535","来源": "/var/lib/docker/volumes/fac362...80535/_data","目的地": "/webapp","司机": "本地",模式": "",RW":真,传播":"}]

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

$ docker inspect blog_postgres-data[{"司机": "本地",标签":空,"Mountpoint": "/var/lib/docker/volumes/blog_postgres-data/_data","Name": "blog_postgres-data",选项": {},范围":本地"}]

谁能帮帮我?我只想知道我的数据卷实际上存在于我的主机上吗?如果是这样,我怎样才能找到它的路径?

解决方案

你的卷目录是 /var/lib/docker/volumes/blog_postgres-data/_data/var/lib/docker 通常挂载在C:UsersPublicDocumentsHyper-VVirtual hard disks.无论如何,您可以通过查看 Docker 设置来检查它.

您可以参考这些文档了解如何在 Windows 上与 Docker 共享驱动器.

顺便说一句,Source 是主机上的位置,Destination 是以下输出中容器内的位置:

坐骑":[{名称":fac362...80535",来源":/var/lib/docker/volumes/fac362...80535/_data",目的地":/webapp",驱动程序":本地",模式":",RW":真,传播":"}]


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

<块引用>

我的主要好奇心是分享图片等很棒,但我该如何分享我的数据?

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

  • 挂载 Docker 卷以托管和重用它

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

    那么你的所有数据都会保存在/path/on/host;你可以备份它,将它复制到另一台机器上,然后用相同的卷重新运行你的容器.

  • 创建并挂载数据容器.

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

    使用--volumes-from运行基于这个容器的其他容器:docker run -d --volumes-from dbstore --name db1 training/postgres,然后db1 生成的所有数据都将保存在容器 dbstore 的卷中.

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

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

<块引用>

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

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

<块引用>

我可以进行备份等吗?

是的,如上所示:-)

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

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

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?

解决方案

Your volume directory is /var/lib/docker/volumes/blog_postgres-data/_data, and /var/lib/docker usually mounted in C:UsersPublicDocumentsHyper-VVirtual hard disks. Anyway you can check it out by looking in Docker settings.

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

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?

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:

  • Mount Docker volume to host and reuse it

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

    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.

  • Create and mount a data container.

    Create a data container: docker create -v /dbdata --name dbstore training/postgres /bin/true

    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.

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

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.

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

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?

Yes, as posted above :-)

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

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