简体   繁体   中英

read file in docker volume from docker container

I have a docker image of the osrm-backend on github.

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.

The path of that file gets defined in the lua script.

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.

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.

.lua code:

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

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.

If your container has bash (for example) then it can be helpful to do something like

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(). Without it everything works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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