问题描述
我只是泊坞化了一个可执行文件,该可执行文件从文件中读取并在文件所在的目录中创建了一个新文件。
I just dockerized an executable that reads from a file and creates a new file in the very directory that file came from.
我想在该设置中使用Docker ,这样就可以避免在生产环境中安装大量第三方库。
I want to use Docker in that setup, so that I avoid installing numerous third-party libraries in the production environment.
我现在的问题:我有文件 / this / is / a .file
在我的基础(主机)文件系统上,并且我的可执行文件应该创建 /this/is/b.file
。
My problem now: I have file /this/is/a.file
on my underlying (host) file system and my executable is supposed to create /this/is/b.file
.
据我所知,完成此操作的唯一机会是通过映射指向 / this / is
的卷然后让可执行文件知道我将其安装在Docker容器中的位置。
As far as I see it, the only chance to get this done is by mapping a volume that points to /this/is
and then let the executable know where I mounted it to in the docker, container.
我对吗?还是有一种方法可以让我通过 docker运行mydockerizedstuff /this/is/a.file
而不使用Docker卷?
Am I right? Or is there a way that I just pass docker run mydockerizedstuff /this/is/a.file
without using Docker volumes?
推荐答案
是的,您需要传入 / this / is
作为卷,可执行文件将写入该卷位置。
You're correct, you need to pass in /this/is
as a volume and the executable will write to that location.
如果您想进一步限制事物,可以传递 /this/is/b.file
作为体积。您需要事先创建它(只需通过 touch
),否则Docker会将其视为一个目录并以此为您创建它,但是您会知道事情不会发生。不能创建 /this/is/c.file
或其他任何东西。
If you want to constrain the thing even more, you can pass /this/is/b.file
as a volume. You need to create it (simply via touch
) beforehand, otherwise Docker will consider it a directory and create it as such for you, but you'll know that the thing won't be able to create /this/is/c.file
or any other thing.
这篇关于Dockerized可执行文件在主机文件系统上的读写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!