Deploy Vespa applications to Docker containers.
!pip install pyvespa
This tutorial assumes that a Vespa application package was defined and stored in the variable
app_package. To illustrate this tutorial, we will use a basic question answering app from our gallery.
from vespa.gallery import QuestionAnswering app_package = QuestionAnswering()
This guide illustrate how to deploy a Vespa application to a Docker container in your local machine. It is required to have Docker installed in the machine you are running this tutorial from. For that reason we cannot run this tutorial in Google Colab as Docker is not available on their standard runtime machines.
VespaDocker instance based on the application package. Set the environment variable
WORK_DIR to the absolute path of the desired working directory.
import os from vespa.deployment import VespaDocker disk_folder = os.path.join(os.getenv("WORK_DIR"), "sample_application") vespa_docker = VespaDocker(port=8089, disk_folder=disk_folder)
deploy method. Behind the scenes,
pyvespa will write the Vespa config files and store them in the
disk_folder, it will then run a Vespa engine Docker container and deploy those config files in the container.
app = vespa_docker.deploy( application_package = app_package, )
That is it, you can now interact with your deployed application through the
from shutil import rmtree rmtree(disk_folder, ignore_errors=True) vespa_docker.container.stop() vespa_docker.container.remove()