简体   繁体   English

从 docker 容器中读取 docker 卷中的文件

[英]read file in docker volume from docker container

I have a docker image of the osrm-backend on github.我在 github 上有一个 osrm 后端的 docker 映像。

When I start the container a profile.lua script is run, which triggers a.cpp file to read the content of the file rastersource.asc.当我启动容器时,会运行 profile.lua 脚本,它会触发 a.cpp 文件来读取文件 rastersource.asc 的内容。

The path of that file gets defined in the lua script.该文件的路径在 lua 脚本中定义。

The C++ file inside the image is located in scr/extractor/rastersource.cpp, the profile.lua and rasterscource.asc are both in e:/docker so they should both be within the volume.镜像中的 C++ 文件位于 scr/extractor/rastersource.cpp 中,profile.lua 和 rasterscource.asc 都在e:/docker docker 中,因此它们都应该在卷中。

What I do is I run the container with:我所做的是运行容器:

docker run -t -v e:/docker:/data osrm/osrm-backend osrm-extract -p /data/profile.lua /data/location-latest.osm.pbf

But now I struggle with defining the absolute path from which the rastersource.cpp should read the file.但是现在我很难定义 rastersource.cpp 应该从中读取文件的绝对路径。

.lua code: .lua 代码:

raster_source = raster:load(
    os.getenv('file/path/which/is/unknown.asc'),
    4.86,    -- longitude min
    5.5,  -- longitude max
    51.95,    -- latitude min
    52.286,  -- latitude max
    169,    -- number of rows
    321     -- number of cols
),

.cpp code .cpp 代码

int RasterContainer::LoadRasterSource(const std::string &path_string,
                                  double xmin,
                                  double xmax,
                                  double ymin,
                                  double ymax,
                                  std::size_t nrows,
                                  std::size_t ncols)
 { 
...
      boost::filesystem::path filepath(path_string);
      if (!boost::filesystem::exists(filepath))
      {
         throw util::RuntimeError(
         path_string, ErrorCode::FileOpenError, SOURCE_REF, "File not found");
      }
}

The Error I get is:我得到的错误是:

terminate called after throwing an instance of 'sol::error'
what():  lua: error: Problem opening file:  (possible cause: "File not found") (at src/extractor/raster_source.cpp:112)

I found a lot of questions regarding this issue but I didn't understand any of the answers.我发现了很多关于这个问题的问题,但我不明白任何答案。

I hope someone here can help me with this.我希望这里有人可以帮助我。 Thanks in advance.提前致谢。

If your file is at e:/docker/rastersource.asc on your host, it should be at /data/rastersource.asc inside your container.如果您的文件位于主机上的e:/docker/rastersource.asc中,则它应该位于容器内的/data/rastersource.asc中。

If your container has bash (for example) then it can be helpful to do something like如果您的容器有 bash (例如),那么执行以下操作可能会有所帮助

docker run -it -v e:/docker:/data osrm/osrm-backend osrm-extract bash

to run your container interactively, in order to manually have a look in the container filesystem and maybe run whatever other commands interactively.以交互方式运行您的容器,以便手动查看容器文件系统并可能以交互方式运行任何其他命令。

I was using os.getenv().我正在使用 os.getenv()。 Without it everything works.没有它一切正常。

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

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