Convert Python Flask APP to Docker Container | Docker | Python Flask
Вставка
- Опубліковано 14 жов 2024
- In this video we will learn about how to create a docker container from a flask app.
we will take an existing flask app and make a docker image from it. we will create a docker file and then use alpine image and python3 and pip to create docker container.
we will use various docker command line RUN, WORKDIR, FROM ,EXPOSE, ENTRYPOINT, CMD
from alpine:latest
RUN apk add --no-cache python3-dev \
&& pip3 install --upgrade pip
WORKDIR /app
COPY . /app
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py"]
Github Repo
=============================
github.com/sel...
Hey, I'm unsure who was the instructor. Seriously, you made things very simple to understand. I was finding it really hard to understand Docker for like 6 months, found many videos but no luck. But, just 24 mins of your explanation, gave me a complete basic understanding of what needs to be done and what we need to look for in Docker. Thank you so much for this.
Very helpful video for dockerize application from back application. Thanks for your support.
Thanks for the tutorial. For some reason, I was facing issues while installing the requirements.txt file because of alpine base image because I was using TensorFlow, scipy, NumPy, etc. I changed to using Ubuntu as the base image and it worked seamlessly.
sames
exactly the sames.
I am using ktrain, which using Tensorflow, so I was hopeful, but it won't accept the entry point, and when I changed that, it still gives me a hard time with the requirements :-/
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 127
For some reason I get "/bin/sh: pip3: not found" error but if you put "RUN apk add py3-pip" before updating pip3 it works fine.
I also got the same error and your fix works for me
thanks for sharing
you're a god
@@anirudrachoudhury3889 I think i might love you
@@anirudrachoudhury3889 Same for me. Thanks Mert
I had also to say MarkupSafe==1.1.1 instead of MarkupSafe==1.0 in requirements.txt file
Thanks Man... Video is crisp and provided exact information... 23 min are properly utilized. Thanks for covering a lot of useful information in right and crisp manner
This is a very useful information. Hopely more in the future about the Flask framework as example with a database.
Very Very Very well explained really conceptual
Thanks. Good info delivered in a clear voice with good sound quality.
Thanks
Best explanation
That's a really good one! Looking forward to try this next days!
Worked very well. Thumbs up for this video!
Great Video, thanks for your sharing
Great tutorial! quick new user question, how would we add a healthcheck to this dockerfile?
What a clear explanation bro. Too good
You are running the application in development mode, is it good practice to promote this docker image ??
Sir, can u tell what is gunicorn with docker
Whats the from "alpine:latest" in my case, if I have just installed docker with no images or containers yet?
If I am developing an app with docket containers then I need to restart docker container everytime which is not feasible. Can you please suggest strategy so that we don't need to restart container and automatically changes will be reflected?
Thank you bro..pls carry on making such tuts videos..your explanation is great..all the best..
Thanks Absar
Really good work.
It's really awesome tq sir.
Can you please make a video with flask Docker Nginx
You da man, man. Thanks a billy
Fantastic video, thank you very much!
Really simple and precise explanations , thank you very much
really nice content and very simple presentation. can you please make one video on deploying frontend(vue js 3) and backend (Flask)
exactly what I was looking for!
thank you very clear and concise
Great tutorial ❤️❤️
Value information ..... Thanks a ton.
The best video ever , thanks a lot
Great video ! Thanks
Thanks for the video!
Can you also make a video on how will you deploy a full fledged flask app that runs using "nginx and gunicorn" or "apache and mod_wsgi" to serve a flask app?
Should we be using docker-compose for such a scenario?
Sure I will make that
If you have any resource for how to deploy full fledged app using nginx and using docker-compose, please share.
great job, just like we were looking for to start with.
Nice explanation ...good job dude :)
Can you build a Docker image with Alpine and run it as a container on CentOS, Ubuntu, Debian, Windows, Mac?
What are the pros and cons? What are the limitations if you can indeed run the container?
Thanks for the awesome tutorial.
thanks for the wonderful effort, i wanted to know whats the use of requirements.txt ? what does it have and is it mandatory to include it in out dockerfile ? Because without it i am able to do everything and container is also running, just my postman is not able to get any response from it inspite of the container instance running.
Requirements.txt file is used by pip (python package manager ) to install project dependencies. It is a standard practice in python development. Also during building of your application image as docker all the dependencies of application must be installed in the docker image so you need to put the requirements.txt file in docker image and then run pip install -r requirements.txt
@@codewithrajranjan oh thankyou so much sir, now my postman is getting response but I am getting some error, api is not working it seems. But when I check it with local host, it works perfectly well, but not working with docker container. Any suggestions on how do I check the error ? As with the local host the error used to pop on the terminal, but now I am just getting a html error on the body part in postman.
@@chetanyat4632 What is the error
@@codewithrajranjan hey I got it fixed, actually I was posting files but the save directory was for the local system, I changed the saving directory to /app and now it works completely fine! But how do I check the uploaded files ? They are in this /app virtual folder. And thankyou so much for the help :)
Great tutorial! Really appreciate your efforts. :)
Thanks Harshil
Thanks alllot you saved me !!
Just note, the container is not killed, it's been stoped, but it's still there. run "docker ps -a" to see it. Better run temporary containers with "docker run --rm ..." to automatically delete the container on exist
have a few services in docker which is currently running and I have another few services from outside the docker ....
Now I have to add all services to one docker file ....
great video man
easy to follow one of the best thx a lot
*Very* helpful, many thanks!
Very nice video, thanks for sharing
Thanks Nageswara
Very good, thanks for the tutorial...
thanks for your explanation!!
Super clear -- thanks!
How to convert them for production and not running by development server
you are awesome keep it up...
Thanks man
what's there in requirements.txt ?
Anybody can help me please with this error
The command '/bin/sh -c pip3 --no-cache-dir install -r requirements.txt' returned a non-zero code: 1
Thanks. This is really useful.
wonderful tutorial!
veru nica tutorial bro, thanks
Thanks man
Very clear!
Great Video, thanks.
Thank you for the excellent tutorial. I tried this out on an existing project so it sadly took me much longer due to the massive dependencies as well. If I do not have a simple API with a GET call setup but an app that does something, how do I access it once the docker image is started? I tried accessing 127.0.0.1:5000 but got nothing.
same problem here, how were you able to fix it?
edit: oh, nvm, i just fix it by binding my host to 0.0.0.0
@@DORAGONROUDO Sorry for seeing this so late. I actually found a great tutorial on how to launch docker images of python flask apps on Pythonise.com
@@sumitmadan768 its okay I just found the solution almost instantly after I commented. Thanks btw xD
Thanks for the nice tutorial!
Thanks man
Thank you!
at 9:42 I get: /bin/sh: pip3: not found
The command '/bin/sh -c apk add --no-cache python3-dev && pip3 install --upgrade pip3' returned a non-zero code: 127
from alpine:latest
# apk package manager for alpine
RUN apk add --no-cache python3-dev \
&& apk add py3-pip \
&& pip install --upgrade pip
WORKDIR /app
COPY . /app
RUN pip --no-cache-dir install -r requirements.txt --ignore-installed
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py"]
Excellent video bro
I have a question: Who teaches you to do the little pause whenever you say "the" or "of"? For example you said
"install it from the...
System"
My co worker does that same thing he's from India
Thanks for the feedback. Will work on it. Can you give some suggestions for improving my accent
@@codewithrajranjan Your accent is fine i understood you perfectly I just had that question to ask your english is fine
Thanks man. But I need to work on my accent so that the global audience doesn't face any problem . BTW which country are you from
@@codewithrajranjan American but i was born in Puerto Rico
Thankyou!!
$ docker run -it -p 5555:5001 flaskapp /bin/sh
File "/bin/sh", line 1 SyntaxError: Non-UTF-8 code starting with '\x80' in file /bin/sh on line 2, but no encoding declared; see python.org/dev/peps/pep-0263/ for details
$ docker run -it -p 5555:5001 flaskapp #no/bin/sh
* Running on 127.0.0.1:5001/ (Press CTRL+C to quit)
But curl refuses connection.
I don't see the error launching the app outside docker on the same machine.
Hello, I am getting curl:(7) Failed to connect to localhost port 8000: connection refused, pls guide.
Try to run on port 5000
@@ricardoribeiro346 Hello Ricardo thank you for your reply, I spin up the AWS cloud9 environment and ran my Docker container there, it ran without any issue. I think the issue was with my Windows PC environment.
great bro
I thought you said SelfTurds.
Hey bro, thanks for the tutorials. I've tried creating my own image with but i'm unable to access the docker port even if i expose it
Here's my docker file:
FROM alpine
#installing dependencies
RUN apk add --update python3
RUN pip3 install flask
#copying build files
#COPY SOURCE DESTINATION
COPY ./ ./
EXPOSE 5000
#default command
ENTRYPOINT [ "python3" ]
CMD ["./app.py"]
here's my flask code:
from flask import Flask
app=Flask(__name__)
@app.route("/")
def hello():
return "Hello World"
if __name__ == "__main__":
print("Serving")
app.run(debug=True,port=5000)
What command your are using for starting the container
@@codewithrajranjan docker run -p5000:5000 basic-flask
@@codewithrajranjan I figured it out. Thanks a lot though
I forgot to add host='0.0.0.0' in the app arguments
If anybody is having problems installing pip or pandas, this is a file I created that worked for me:
github.com/PavlySz/Binary-Classifier/blob/master/Dockerfile
It should be RUN apk add --no-cache python3-dev py3-pip
py3-pip (missing):
required by: world[py3-pip]
python3-dev (missing):
required by: world[python3-dev]
facing this error after running your command
I understand this is so late but whoever is trying this docker build and found an issue(executor failed running [/bin/sh -c apk add --no-cache python3-dev && pip3 install --upgrade pip]: exit code:) with pip3, please use the below command,
from alpine:latest
RUN apk add --no-cache python3-dev \
&& apk update \
&& apk add py-pip
This should solve your issue!!
Also, you could face an issue with markupsafe and six because it got updated so use this instead in the requirements.txt
MarkupSafe==1.1.1
pytz==2018.5
six==1.16.0
Werkzeug==0.14.1
Great video, thank you very much!