I am quite new to docker. I am trying to deliver some scores via my h2o models through docker in real time (have not tried this yet: link). Here is my Dockerfile and docker-compose/yml.
FROM python:3.9
WORKDIR /app
RUN apt-get update && apt-get install -y default-jre
RUN pip install h2o==3.38.0.3
RUN pip install pandas==1.3.5
COPY . /app
#EXPOSE 8000
CMD ["python", "my_models.py"]
docker-compose.yml:
version: '3'
services:
click_app:
image: h2oai/h2o-open-source-k8s
container_name: click_models
restart: unless-stopped
build: .
ports:
- "8001:8001"
and my code:
h2o.init(port=23023, nthreads=10)
def main():
df_h2o = h2o.import_file('input.csv')
df_h2o["PhoneNumber"] = df_h2o["PhoneNumber"].ascharacter()
dfScore = df_h2o[df_h2o['NotDateMonth']==5]
ms1gbm, ms1rf, ms1glm, ms2gbm, ms2rf, ms2glm = CallModels()
predictions = Score(ms1gbm, ms1rf, ms1glm, ms2gbm, ms2rf, ms2glm, dfScore)
print("NOTIFY...", predictions)
return 0
if __name__ == '__main__':
print(sys.argv)
main()
So as long as I have restart: unless-stopped in my yml file, h2o server starts and my code runs doing the scoring and the process keeps repeating infinitely (reinitiating the same h2o over and over again). If I remove it of course it only runs once. What I want is to initiate h2o once keep the container up and whenever a new dataset shows up then do the scoring. What would be the ways to achieve this?
You would be better off using a MOJO wrapped in a web service. Using a full H2O-3 instance for real-time scoring is not recommended.
Here is a link to a really old, but really simple, example:
https://github.com/h2oai/app-consumer-loan/blob/master/src/main/java/org/gradle/PredictServlet.java
The link you provided above to the eScorer tutorial assumes you have an H2O AI Cloud instance with the model already hosted.
Whereas the simple OSS example directly instantiates a java servlet container and has the model inside.
You can try to dockerize this simple example if you want, but that's probably overkill. If you dockerize it, I suggest running
docker rundirectly and not usingdocker composeat all.