This is a very simple and generic Flask App that uses GET and Post methods. It also uses a fun API.
- Clone this repository to a directory of your choice on your terminal.
- Command to clone:
git clone https://github.com/iamAngelSH/flask-docker-hello-world.git
- Step in the repository directory
- Change Directory
cd flask-docker-hello-world
- Here you should have all the contents you need.
- Having Docker running already on your computer, we can get started with the Flask App.
- Let's build the image
- Run docker-compose up in the same directory you are in
docker-compose up
THESE NEXT STEPS IS TO USE THE FLASK APP ON THE WEB 🕸️
- If you want to skip the web browser part, SKIP TO THIS SECTION
- Open a web browser
- Once the image is the done building you should get the following link:
- However, we will not be using that!
- Since port 5000 is for the server running on the docker container, we need to use the port running on our local machine.
- Use the following:
- Congrats 🥳 Flask App is up and running. You will see a menu on your web browser with what you can do on this Flask App.
Although we do have our flask app running, it is always good to test our routes and make sure they work appropriately.
- Having your flask docker container still running, open a new terminal.
- Change into the directory that you have the repository (Flask Project) stored in.
- Change into the repository directory
cd ~Path_to_repo
- Once you are in the reposiotry directory, we run another docker-compose command
- This command will let us execute a python script to test the routes in our flask app and should return values via the terminal.
docker-compose exec web python make-requests.py
- Once you run this command, there will be results logged on your terminal.
- If the status code is 200 (ok), you will get the following:
pong!
EDIFNOC
4
- If the status code is not 200, you will see something similar to the following:
{'code': 400, 'name': 'Bad Request', 'description': 'Failed to decode JSON object: None'}
- Tada!! 🥳 You have hit all the targets in the flask app!