【问题标题】:How to mount a volume from a local machine on Podman如何在 Podman 上从本地计算机挂载卷
【发布时间】:2021-11-16 18:07:03
【问题描述】:

我正在尝试使用 Podman 进行本地开发。我的想法是使用本地文件夹并将其与我将运行我的应用程序的容器同步。

我发现-v 选项,如果我使用 Docker,我会使用服务器机器,正如它在文档 -v Bind mount a volume into the container. Volume src will be on the server machine, not the client 中所说的那样。因此,当我使用该选项时,该文件夹未安装,当我使用 podman exec -it application bash 访问它时找不到它。

有没有办法解决这个问题? 我想要的东西相当于:

docker run -v localFolder:/remoteFolder application

localFolder 是我本地机器中的路径,它将映射到容器上的remoteFolder

【问题讨论】:

    标签: podman


    【解决方案1】:

    我建议使用--mount 标志而不是-v--volume。我假设您希望能够在容器中运行应用程序时轻松修改主机上的文件。这是一个简单的例子:

    首先,该目​​录需要存在于主机上:

    user@host:~$ mkdir ~/localFolder
    

    ~/localFolder 目录中创建一个文件,其中包含一些文本:

    user@host:~$ echo "Sample Text" > ~/localFolder/test
    

    然后,使用绑定挂载启动您的容器。此示例以非特权用户身份使用带有 Debian Bullseye 映像的 podman 无根容器。注意:最好对源(主机)和目标(容器)目录使用绝对路径:

    user@host:~$ podman run -it --rm --mount type=bind,source=/home/$USER/localFolder,target=/remoteFolder docker.io/debian:bullseye /bin/bash
    

    现在您的~/localFolder 目录可以在您的容器内作为/remoteFolder 访问:

    root@f724a0337f76:/# cat /remoteFolder/test 
    Sample Text
    

    您可以在此文件夹中添加新文件或修改现有文件,而无需重新启动容器。

    Docker 在这里对绑定挂载有很好的解释:https://docs.docker.com/storage/bind-mounts/

    【讨论】:

    • 恐怕我仍然收到类似Error: statfs ~/localFolder: no such file or directory的错误
    • 您是在容器中还是在主机上收到该错误?
    • 当 podman 使用 VM 时(例如在 Mac 上),我们需要先将主机挂载到 VM 中,然后再从 VM 挂载到容器中。遗憾的是这里涉及到 3 层。
    • 这个错误在我认为的容器中(主机有那个文件)。那么,如何将主机挂载到虚拟机中呢?
    • 错误来自虚拟机上的podman,容器从未启动。 this 是功能请求。
    猜你喜欢
    • 2015-07-14
    • 2022-10-10
    • 2017-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2020-08-29
    相关资源
    最近更新 更多