Last active
March 17, 2022 16:50
-
-
Save ashutosh1919/9c99962a02cf92849af99324c7afecb6 to your computer and use it in GitHub Desktop.
Gists for Dockerized Flask application
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
from flask import Flask, jsonify | |
import pymongo | |
from pymongo import MongoClient | |
app = Flask(__name__) | |
def get_db(): | |
client = MongoClient(host='test_mongodb', | |
port=27017, | |
username='root', | |
password='pass', | |
authSource="admin") | |
db = client["animal_db"] | |
return db | |
@app.route('/') | |
def ping_server(): | |
return "Welcome to the world of animals." | |
@app.route('/animals') | |
def get_stored_animals(): | |
db = get_db() | |
_animals = db.animal_tb.find() | |
animals = [{"id": animal["id"], "name": animal["name"], "type": animal["type"]} for animal in _animals] | |
return jsonify({"animals": animals}) | |
if __name__=='__main__': | |
app.run(host="0.0.0.0", port=5000) |
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
FROM python:3.6 | |
ADD . /app | |
WORKDIR /app | |
RUN pip install -r requirements.txt |
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
flask | |
pymongo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment