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...

КОМЕНТАРІ • 118

  • @techtalks_India
    @techtalks_India 2 роки тому +4

    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.

  • @virendrabhati6685
    @virendrabhati6685 2 роки тому

    Very helpful video for dockerize application from back application. Thanks for your support.

  • @aakupsp
    @aakupsp 4 роки тому +4

    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.

    • @dylankendrick27
      @dylankendrick27 4 роки тому +1

      sames
      exactly the sames.

    • @Mel-be6mg
      @Mel-be6mg 4 роки тому +1

      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

  • @mertyertugrul
    @mertyertugrul 4 роки тому +31

    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.

    • @anirudrachoudhury3889
      @anirudrachoudhury3889 3 роки тому

      I also got the same error and your fix works for me
      thanks for sharing

    • @PrAnKs1223
      @PrAnKs1223 3 роки тому

      you're a god

    • @malthereipurth8293
      @malthereipurth8293 3 роки тому

      @@anirudrachoudhury3889 I think i might love you

    • @jpmacveigh
      @jpmacveigh 3 роки тому

      @@anirudrachoudhury3889 Same for me. Thanks Mert

    • @jpmacveigh
      @jpmacveigh 3 роки тому +1

      I had also to say MarkupSafe==1.1.1 instead of MarkupSafe==1.0 in requirements.txt file

  • @himanshukarki
    @himanshukarki 2 роки тому

    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

  • @jayhu6075
    @jayhu6075 4 роки тому +3

    This is a very useful information. Hopely more in the future about the Flask framework as example with a database.

  • @mujahidali2369
    @mujahidali2369 3 роки тому

    Very Very Very well explained really conceptual

  • @zahirjacobs716
    @zahirjacobs716 5 років тому +4

    Thanks. Good info delivered in a clear voice with good sound quality.

  • @toprated8832
    @toprated8832 2 роки тому

    Best explanation

  • @Bloome_BlueFolf
    @Bloome_BlueFolf 2 роки тому

    That's a really good one! Looking forward to try this next days!

    • @Bloome_BlueFolf
      @Bloome_BlueFolf 2 роки тому

      Worked very well. Thumbs up for this video!

  • @韋辰姜-j6i
    @韋辰姜-j6i 3 роки тому

    Great Video, thanks for your sharing

  • @maccabikid
    @maccabikid 4 роки тому +3

    Great tutorial! quick new user question, how would we add a healthcheck to this dockerfile?

  • @mkalicharan
    @mkalicharan 3 роки тому

    What a clear explanation bro. Too good

  • @rajun6713
    @rajun6713 4 роки тому +1

    You are running the application in development mode, is it good practice to promote this docker image ??

  • @2mahender
    @2mahender 2 роки тому

    Sir, can u tell what is gunicorn with docker

  • @movildrivesystems5176
    @movildrivesystems5176 4 роки тому +2

    Whats the from "alpine:latest" in my case, if I have just installed docker with no images or containers yet?

  • @bhargavakhani4921
    @bhargavakhani4921 3 роки тому

    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?

  • @absar66
    @absar66 5 років тому +1

    Thank you bro..pls carry on making such tuts videos..your explanation is great..all the best..

  • @ishankhandelwal2519
    @ishankhandelwal2519 4 роки тому +1

    Really good work.

  • @prabhashswain1878
    @prabhashswain1878 3 роки тому

    It's really awesome tq sir.
    Can you please make a video with flask Docker Nginx

  • @localmadisonlaughs8585
    @localmadisonlaughs8585 2 роки тому

    You da man, man. Thanks a billy

  • @fancylad2006
    @fancylad2006 5 років тому +4

    Fantastic video, thank you very much!

  • @abdullahmoiz8151
    @abdullahmoiz8151 4 роки тому

    Really simple and precise explanations , thank you very much

  • @shrihanscreativeworld8813
    @shrihanscreativeworld8813 2 роки тому

    really nice content and very simple presentation. can you please make one video on deploying frontend(vue js 3) and backend (Flask)

  • @austinpowell7003
    @austinpowell7003 5 років тому +7

    exactly what I was looking for!

  • @jesse1leonard
    @jesse1leonard 4 роки тому

    thank you very clear and concise

  • @schnookycoder8324
    @schnookycoder8324 3 роки тому

    Great tutorial ❤️❤️

  • @anukoolsrivastava4235
    @anukoolsrivastava4235 4 роки тому

    Value information ..... Thanks a ton.

  • @habibverse
    @habibverse 3 роки тому

    The best video ever , thanks a lot

  • @jpmacveigh
    @jpmacveigh 3 роки тому

    Great video ! Thanks

  • @gauravstud
    @gauravstud 5 років тому +2

    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?

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      Sure I will make that

    • @lukeshpatil9055
      @lukeshpatil9055 5 років тому +1

      If you have any resource for how to deploy full fledged app using nginx and using docker-compose, please share.

  • @ninexussolutions
    @ninexussolutions 3 роки тому

    great job, just like we were looking for to start with.

  • @nikitashanbhag3c711
    @nikitashanbhag3c711 4 роки тому

    Nice explanation ...good job dude :)

  • @elachichai
    @elachichai 4 роки тому

    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?

  • @kelvinkiumi
    @kelvinkiumi 4 роки тому

    Thanks for the awesome tutorial.

  • @chetanyat4632
    @chetanyat4632 5 років тому

    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.

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      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

    • @chetanyat4632
      @chetanyat4632 5 років тому

      @@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.

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      @@chetanyat4632 What is the error

    • @chetanyat4632
      @chetanyat4632 5 років тому

      @@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 :)

  • @hd3adpool
    @hd3adpool 4 роки тому +1

    Great tutorial! Really appreciate your efforts. :)

  • @Abhishek-jy4ul
    @Abhishek-jy4ul 4 роки тому

    Thanks alllot you saved me !!

  • @doaa1918
    @doaa1918 4 роки тому

    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

  • @xamguide2914
    @xamguide2914 5 років тому

    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 ....

  • @amolsingh5882
    @amolsingh5882 3 роки тому

    great video man

  • @nsv.2344
    @nsv.2344 5 років тому

    easy to follow one of the best thx a lot

  • @prestonjensen6172
    @prestonjensen6172 4 роки тому

    *Very* helpful, many thanks!

  • @Nageswararao93
    @Nageswararao93 5 років тому

    Very nice video, thanks for sharing

  • @dders2
    @dders2 4 роки тому

    Very good, thanks for the tutorial...

  • @monsieurdung
    @monsieurdung 4 роки тому

    thanks for your explanation!!

  • @JulianHarris
    @JulianHarris 4 роки тому

    Super clear -- thanks!

  • @rajeshwaris6663
    @rajeshwaris6663 4 роки тому

    How to convert them for production and not running by development server

  • @ravikantitare683
    @ravikantitare683 4 роки тому

    you are awesome keep it up...

  • @jagveeryadav7902
    @jagveeryadav7902 2 роки тому

    what's there in requirements.txt ?

  • @adriancarvajal6526
    @adriancarvajal6526 4 роки тому +1

    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

  • @leamon9024
    @leamon9024 5 років тому

    Thanks. This is really useful.

  • @RaghavaIndra
    @RaghavaIndra 4 роки тому

    wonderful tutorial!

  • @vinsmokearifka
    @vinsmokearifka 5 років тому

    veru nica tutorial bro, thanks

  • @hkg3june
    @hkg3june 5 років тому

    Very clear!

  • @defaoite_cormac
    @defaoite_cormac 5 років тому

    Great Video, thanks.

  • @sumitmadan768
    @sumitmadan768 5 років тому +1

    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.

    • @DORAGONROUDO
      @DORAGONROUDO 4 роки тому +1

      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

    • @sumitmadan768
      @sumitmadan768 4 роки тому

      @@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

    • @DORAGONROUDO
      @DORAGONROUDO 4 роки тому

      @@sumitmadan768 its okay I just found the solution almost instantly after I commented. Thanks btw xD

  • @georgezviadgoglodze7810
    @georgezviadgoglodze7810 5 років тому

    Thanks for the nice tutorial!

  • @gulsicka2486
    @gulsicka2486 4 роки тому

    Thank you!

  • @zentekvideogames3589
    @zentekvideogames3589 4 роки тому

    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

    • @aminebenamor8445
      @aminebenamor8445 3 роки тому +1

      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"]

  • @MistaT44
    @MistaT44 5 років тому

    Excellent video bro

  • @89elmonster
    @89elmonster 5 років тому

    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

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      Thanks for the feedback. Will work on it. Can you give some suggestions for improving my accent

    • @89elmonster
      @89elmonster 5 років тому

      @@codewithrajranjan Your accent is fine i understood you perfectly I just had that question to ask your english is fine

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      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

    • @89elmonster
      @89elmonster 5 років тому

      @@codewithrajranjan American but i was born in Puerto Rico

  • @rijwanmohammed1309
    @rijwanmohammed1309 5 років тому +1

    Thankyou!!

  • @elachichai
    @elachichai 4 роки тому

    $ 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.

  • @2113kunvar
    @2113kunvar 4 роки тому

    Hello, I am getting curl:(7) Failed to connect to localhost port 8000: connection refused, pls guide.

    • @ricardoribeiro346
      @ricardoribeiro346 4 роки тому +1

      Try to run on port 5000

    • @2113kunvar
      @2113kunvar 4 роки тому +1

      @@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.

  • @bursoft8165
    @bursoft8165 5 років тому

    great bro

  • @thoeer913
    @thoeer913 3 роки тому

    I thought you said SelfTurds.

  • @sudeep.g
    @sudeep.g 5 років тому +1

    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)

    • @codewithrajranjan
      @codewithrajranjan  5 років тому

      What command your are using for starting the container

    • @sudeep.g
      @sudeep.g 5 років тому

      @@codewithrajranjan docker run -p5000:5000 basic-flask

    • @sudeep.g
      @sudeep.g 5 років тому +3

      @@codewithrajranjan I figured it out. Thanks a lot though
      I forgot to add host='0.0.0.0' in the app arguments

  • @PaulBlxck
    @PaulBlxck 4 роки тому

    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

  • @adamraszkiewicz6300
    @adamraszkiewicz6300 4 роки тому

    It should be RUN apk add --no-cache python3-dev py3-pip

    • @newswritter8648
      @newswritter8648 4 роки тому

      py3-pip (missing):
      required by: world[py3-pip]
      python3-dev (missing):
      required by: world[python3-dev]
      facing this error after running your command

  • @techtalks_India
    @techtalks_India 2 роки тому

    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

  • @EnglishRain
    @EnglishRain 4 роки тому

    Great video, thank you very much!