gpt4 book ai didi

c++ - 从 docker 容器中读取 docker volume 中的文件

转载 作者:行者123 更新时间:2023-12-05 05:36:34 25 4
gpt4 key购买 nike

我在 github 上有一个 osrm-backend 的 docker 镜像。

当我启动容器时,会运行一个 profile.lua 脚本,它会触发一个 .cpp 文件来读取文件 rastersource.asc 的内容。

该文件的路径在 lua 脚本中定义。

图像中的C++文件位于scr/extractor/rastersource.cpp,profile.lua 和 rasterscource.asc 都在 e:/docker 中,所以它们应该都在卷内。

我所做的是运行容器:

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

但现在我很难定义 rastersource.cpp 应该从中读取文件的绝对路径。

.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代码

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");
}
}

我得到的错误是:

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)

我发现了很多关于这个问题的问题,但我不明白任何答案。

我希望这里有人可以帮助我解决这个问题。提前致谢。

最佳答案

如果您的文件位于主机上的 e:/docker/rastersource.asc,则它应该位于容器内的 /data/rastersource.asc

如果您的容器有 bash(例如),那么做类似的事情会很有帮助

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

以交互方式运行您的容器,以便手动查看容器文件系统并可能以交互方式运行任何其他命令。

关于c++ - 从 docker 容器中读取 docker volume 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73290446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com