Setting Up Flask
Assuming docker installed in your ubuntu 18.04 instance. Move into your project path.
Example : /home/gisak/projects/python/logics/pic_holdr/pic_holdr/pic_flk_holdrFiles present within project folder were below.
Contents present within requirements.txt file :
flask==1.1.1
Contents present within Dockerfile :
FROM ubuntu:18.04 MAINTAINER GisakInc 'support@gisakinc.com' RUN apt-get update -y \ apt-get install -y python3-pip python3-dev COPY ./requirements.txt /app/requirements.txt WORKDIR /app RUN pip3 install -r requirements.txt COPY . /app ENTRYPOINT [ "/usr/bin/python3" ] CMD ["base.py"]
Contents present within base.py :
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(host='0.0.0.0', port=9302)
Creating Virtual Environment with python3 :
python3.6 -m virtualenv vbase_flk
Running Flask Server:
python base.py
Building Docker Image:
Note: current path is project base path. we specified project contents in current path(dot symbol).`sudo docker build -t pic_flk_holder:0.0.03 .`Once its completed, Build will present in Docker List.
sudo docker imagesAfter docker image created, we have to test the container by running it.
sudo docker run -d -p 9032:9032 pic_flk_holder:0.0.03Once docker started running, we can see it by below command.
That's it. Hope this helps!
Really good one.
ReplyDelete