Predictive Hacks

How to Compose a Flask API with Docker

You can compose a Flask API as follows: The project structure will look like:

.
├── docker-compose.yaml
├── app
    ├── Dockerfile
    ├── requirements.txt
    └── app.py

The docker-compose.yml will be:

version: '3' 
services: 
  web: 
    build: app 
    ports: 
      - '5000:5000'

The Dockerfile will be:

FROM python:3.7-alpine 
WORKDIR /app 
COPY requirements.txt /app
RUN pip3 install -r requirements.txt 
COPY . /app 
ENTRYPOINT ["python3"] 
CMD ["app.py"]

The requirements.txt will be:

flask

and the app.py will be:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
	return "Hello World!"

if __name__ == '__main__':
	app.run(host='0.0.0.0')

Of course the files above is just an example of a basic “Hello World!” Flask API

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s