make build make run
Created
March 28, 2018 14:30
-
-
Save padawin/0c91d2346023a0603fc741ee25b8f0a3 to your computer and use it in GitHub Desktop.
Docker python example
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-stretch | |
WORKDIR /app | |
COPY requirements.txt main-flask.py main-tornado.py script.py /app/ | |
RUN pip3 install -r requirements.txt | |
# CMD python3 main-tornado.py | |
# CMD FLASK_APP=main-flask.py flask run | |
CMD python3 main-flask.py |
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 | |
from script import some_function | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return some_function() | |
app.run('0.0.0.0') |
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
import tornado.ioloop | |
import tornado.web | |
from script import some_function | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
response_body = some_function() | |
self.write(response_body) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
app = make_app() | |
app.listen(8888) | |
tornado.ioloop.IOLoop.current().start() |
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
build: | |
docker build . | |
run: | |
docker run -p 5000:5000 python-example |
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
tornado | |
flask |
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
def some_function(): | |
return "Hello World" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment