简体   繁体   English

python + docker:docker卷挂载错误,数据静默丢失

[英]python+docker: docker volume mounting with bad perms, data silently missing

I'm running into an issue without volume mounting, combined with the creation of directories in python. 我遇到了一个问题,没有卷挂载,加上在python中创建目录。

Essentially inside my container, I'm writing to some path /opt/… , and I may have to make the path (which I'm using os.makedirs for) 基本上,在我的容器内,我正在写一些路径/opt/… ,并且可能必须创建路径(我使用os.makedirs作为路径)

If I mount a host file path like -v /opt:/opt , with bad "permissions" where the docker container does not seem to be able to write to, the creation of the path inside the container DOES NOT FAIL. 如果我安装了-v /opt:/opt类的主机文件路径,并且其中的“权限”很差,而docker容器似乎无法写入,则在容器内部创建路径不会失败。 The makedirs(P) works, because inside the container, it can make the dir just fine, because it has sudo permissions. makedirs(P)之所以有效,是因为它在容器内可以使dir正常,因为它具有sudo权限。 However, nothing gets written, silently, on the host at /opt/… . 但是,在/opt/…主机上没有任何内容被静默地写入。 The data just isn't there, but no exception is ever raised. 数据不存在,但从未引发异常。

If I mount a path with proper/open permissions, like -v /tmp:/opt , then the data shows up on the host machine at /tmp/… as expected. 如果我安装了具有适当/打开权限的路径,例如-v /tmp:/opt ,那么数据将按预期显示在主机上的/tmp/…

So, how do I not silently fail if there are no write permissions on the host on the left side of the -v argument?\\ 因此,如果在-v参数左侧的主机上没有写许可权,我该如何默默地失败?\\

EDIT: my question is "how do I detect this bad deployment scenario, crash, and fail fast inside the container, if the person who deploys the container, does it wrong"? 编辑:我的问题是“如果部署容器的人,我该如何检测这种不良的部署方案,崩溃并在容器内部快速失败,这是不对的”? Just silently not writing data isn't acceptable. 只是默默地不写数据是不可接受的。

The bad mount is root on the host right, and the good mount is the user in the Docker group on the host? 错误的安装是主机正确的根,正确的安装是主机上的Docker组中的用户吗? Can you check the user/group of the mounted /opt ? 您可以检查已安装的/opt的用户/组吗? It should be different than that of /tmp . 它应该不同于/tmp

You could expect a special file to exist in /opt and fail if it's not present 您可能希望/ opt中存在一个特殊文件,如果不存在该文件则会失败

if not os.path.exists(PATH):
    raise Exception("could not find PATH: file missing or failed to mount /opt")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM