Docker绑定安装目录中的文件未更新 [英] Files within Docker bind mount directory not updating

查看:192
本文介绍了Docker绑定安装目录中的文件未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker bind mount映射由Ubuntu生成的主机 / dev / serial / 文件夹(其中包含与串行设备(例如 / dev / ttyUSB0 )。我正在使用的完整docker容器运行命令是

I am using docker bind mount to map the host /dev/serial/ folder generated by Ubuntu (which contains identifying symlinks to serial devices such as /dev/ttyUSB0). The full docker container run command I am using is

docker run -d --restart always --privileged=true -v /dev/serial:/dev/serial DOCKER_IMAGE_NAME

在第一次运行时效果很好,但是如果使用串行设备断开并重新连接后,将重新创建符号链接。此更改不会传播到docker容器中,而是在docker容器中找到一个空的 / dev / serial 文件夹。我测试了手动在主机上以及此目录中的docker容器内创建文件,奇怪的是,在两种情况下,一个都没有更新。

This works fine at first run, however if the serial device is disconnected and reconnected, the symlinks are recreated. This change does not propagate into the docker container and instead the docker container finds an empty /dev/serial folder. I tested manually creating a file on the host and within the docker container in this directory as well, and strangely the change on one was not updated in the other in both cases.

音量显示为

{
    "Type": "bind",
    "Source": "/dev/serial",
    "Destination": "/dev/serial",
    "Mode": "",
    "RW": true,
    "Propagation": "rprivate"
}

编辑:Ubuntu在两个目录中创建符号链接,< / dev / serial 路径 by-id >文件夹。

Ubuntu creates the symlinks within two directories, by-path and by-id underneath the /dev/serial folder.

推荐答案

绑定安装基于inode,并且在删除并重新创建文件后,绑定安装会损坏。在容器重新启动之前,这些更改不会传播到绑定安装,因此它将选择新的inode。

Bind mounts are based on inodes and when the file is deleted and recreated then the bind-mount is broken. These changes aren't propagated to the bind-mount until a container restart so it picks the new inode.

这种情况的解决方案(删除并重新创建文件)是而是挂载父目录,因此在您的情况下,可以使用 -v / dev:/ dev 挂载。当然,这会将/ dev暴露给容器,因此请谨慎处理。

A solution for this case (files are deleted and recreated) is to mount the parent directory instead, so in your case you can mount using -v /dev:/dev. Of course this will expose /dev to the container so handle it with care.

这篇关于Docker绑定安装目录中的文件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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