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