Some minor fixes working with git project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/Soluto/python-flask-sklearn-docker-template | |
Building the image | |
===================== | |
docker build . -t prodexample -f . | |
docker run -p 5014:5003 -d prodexample | |
Dockerfile | |
=========== | |
#Had to change base image to use this | |
FROM python:3.6 | |
WORKDIR /app/ | |
COPY requirements.txt /app/ | |
COPY . /app/ | |
RUN pip install -r ./requirements.txt | |
#ENV ENVIRONMENT production | |
COPY main.py __init__.py /app/ | |
RUN pip install -r requirements.txt | |
#Added below two lines to run the app with base image changes | |
ENTRYPOINT ["python"] | |
CMD ["main.py"] | |
Checking Logs | |
=============== | |
docker logs 'container_id' | |
ModuleNotFoundError: No module named 'sklearn.linear_model._base' | |
Kill all running containers | |
============================= | |
docker container kill $(docker container ls -q) | |
Modified Code | |
============= | |
#!flask/bin/python | |
import os | |
from flask import Flask | |
from flask import request | |
import pandas as pd | |
from sklearn import linear_model | |
import pickle | |
# creating and saving some model | |
reg_model = linear_model.LinearRegression() | |
reg_model.fit([[1.,1.,5.], [2.,2.,5.], [3.,3.,1.]], [0.,0.,1.]) | |
pickle.dump(reg_model, open('some_model.pkl', 'wb')) | |
app = Flask(__name__) | |
@app.route('/isAlive') | |
def index(): | |
return "true" | |
@app.route('/prediction/api/v1.0/some_prediction', methods=['GET']) | |
def get_prediction(): | |
feature1 = float(request.args.get('f1')) | |
feature2 = float(request.args.get('f2')) | |
feature3 = float(request.args.get('f3')) | |
loaded_model = pickle.load(open('some_model.pkl', 'rb')) | |
prediction = loaded_model.predict([[feature1, feature2, feature3]]) | |
return str(prediction) | |
if __name__ == '__main__': | |
#if os.environ['ENVIRONMENT'] == 'production': | |
# app.run(port=80,host='0.0.0.0') | |
#if os.environ['ENVIRONMENT'] == 'local': | |
app.run(port=5003,host='0.0.0.0') | |
commands | |
=========== | |
docker build . -t prodexample -f . | |
docker run -p 5015:5005 -d prodexample | |
docker run -d -p 5013:5003 lr | |
http://0.0.0.0:5015/isAlive | |
http://0.0.0.0:5015/prediction/api/v1.0/some_prediction?f1=4&f2=4&f3=4 |
Keep Exploring!!!
Best practice for container-based deployment system
- Use a container-orchestration system such as Kubernetes or Docker Swarm to manage and deploy your containers.
- Use a container registry such as Docker Hub or Quay to store and manage your container images.
- Use a continuous integration system such as Jenkins or Travis CI to automate the build and deployment of your containers.
- Monitor your containers and applications using tools such as Prometheus or Grafana to ensure they are running optimally.
- Use a service mesh such as Istio or Linkerd to manage the communication between your services.
- Use a logging and monitoring system such as ELK or Splunk to track the performance of your containers and applications.
- Use a security scanning tool such as Twistlock or Aqua Security to ensure your containers are secure.
- Use a configuration management system such as Ansible or Chef to manage the configuration of your containers.
- Use a deployment automation tool such as Helm or Terraform to automate the deployment of your containers.
- Use a cloud provider such as Amazon Web Services or Google Cloud Platform to host your containers.
Keep Exploring!!!
No comments:
Post a Comment