Skip to content

Indexing images locally

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"
}
will attempt to read the file from the local store "/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/"
and run the following:
python3 -m http.server 8222
Now modify the paths of the images in the data to be indexed or searched to start with: 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"
}
The original local path of the image was /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 --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:latest
The source and target above should be changed to correspond to your needs.