Indexing images on a host machine
When indexing or searching with images, Marqo accepts a pointer to a local file or a url. For some use cases, images may be stored locally and referenced using a local file pointer. By default, Marqo running within Docker will not be able to access these. For example, a document given by the following:
{
"My_Image": "/directory/where_you_keep_or_save_images_for_searching/images/image5.png",
"Description": "The hippopotamus, also called the common hippopotamus or river hippopotamus, is a large semiaquatic mammal native to sub-Saharan Africa",
"_id": "hippo-facts5",
}
"/directory/where_you_keep_or_save_images_for_searching/images/image5.png"
. However, the default settings may not allow the file to be read.
1. Using a simple http server
A simple http server can be used to allow access to files in a local directory through localhost. These can then be accessed from within the docker container. The setup is described below.
Navigate to the directory where the images for indexing and searching will be:
cd "/directory/where_you_keep_or_save_images_for_searching/"
python3 -m http.server 8222
http://host.docker.internal:8222/
instead of the local path:
/directory/where_you_keep_or_save_images_for_searching/
.
For example, a document that wants to use a file with a local address of /directory/where_you_keep_or_save_images_for_searching/images/image5.png
would become:
{
"My_Image": "http://host.docker.internal:8222/images/image5.png",
"Description": "The hippopotamus, also called the common hippopotamus or river hippopotamus, is a large semiaquatic mammal native to sub-Saharan Africa",
"_id": "hippo-facts5",
}
/directory/where_you_keep_or_save_images_for_searching/images/image5.png
but now for docker to access it it becomes http://host.docker.internal:8222/images/image5.png
.
If you want to view the files that are being served on localhost, you can use a web-browser to view them at http://localhost:8222/
. Note this address is different to what docker uses.
The same pattern holds for images that are used for searching. Those images should reside (or be saved in) the directory (or a sub-directory) from where the http server was run.
2. Mounting the local drive to Docker
To enable local files to be read, the Docker run command can be updated to include mounting local directories so they are accessible from within the Docker using --mount
via the following;
docker rm -f marqo;docker run --name marqo --mount type=bind,source=/user/someone/images/,target=/user/someone/images/ -it -p 8882:8882 marqoai/marqo:latest
source
and target
above should be changed to correspond to your needs.