You are on page 1of 5
How to Serve a Flask App with Amazon Lightsail Containers Ta get stare youll ned an WS acount and mustinetal Docksr the AWS Command line Interface (Cl tel nd the Los Conta \Ushtsalet olan on your system. Follow the provide nk if you dont have some of hose Create the application orpete the folowing sep on ou cal machin that running Docker These tps walk you soup the process often the Fas ppcaton es Create a nen project directory and switch to that directory. [Firesin Tightsait-contatners-fiasi a8 cd Tighteail-containere laa Create a new fle, app.py. and paste the fallowing code into the fle Save the fle, ron (iaak Enport Flask be = Flask(_nane_) bno-rourer ef hello.yorié() return “Mello, workal® app. ran(nosta"0.0.050", portesaa0) ‘This min mal ask application contains 2 single function hello_ world that i triggered when the route "is requested, Wren run, his application binds to all1Ps on the system (°0.00" and lstons on port $000 (this is the default Flask port Create 2 new fle, requirements it. Et the file and 20d the following. Save the Se ia ronuinenents.ta les are used to specifying what Python packages are required by the pplication, For this minimal Flask appliation ‘theres only one required package, Flask Create a new fle, Dacker#ite Et the flle and ade the following Save the file ‘et base inage (host 05) Rom pytnon:3.8-alpine Ose 5000/tep Set the working directory in the container neboR 200 copy the dependencies Fe to the working directory Install any dependencies copy tne content of the local are directory to the working directory Soaclfy the comand to run on contatnae start pytnon®, *./app-py") ‘The Python alpine image ensures the resulting container i as compact and smalls possible. The commané to un wien the container Sorts the some af cun from the commane Fne: python ape py Your project directory should contain the folowing fis: 18 Build the container Complete the following steps to build and tes: the container image locally Bull the container using Docker. Execute the following command from the same directory asthe Dockerfle: [cer ad 4 Finsicortainer This command builds 9 container using the Dackefle in the curent directory an tags the container “flask-containe. ‘once the container build is done, test the Flask application locally by unning the container: teeter ron

You might also like