Docker Flask issues

have a few questions that I am hoping someone can answer here. I realize I have knowledge gap and I am hoping someone here can fill it or at least point me towards the right direction.

I had built a Flask API that I could run inside a Docker Container on Ubuntu OS. To create a Swagger API Documentation, I added to my Flask application:

from flask_swagger_ui import get_swaggerui_blueprint

Rather than moving forward, I stopped the Docker and ran it again and as expected, It resulted in “502 Gateway error”. Upon Checking Docker logs here is what I noticed:

ModuleNotFoundError: No module named 'flask_swagger_ui'

I understood this problem as I needed to add this dependency inside my docker. I added the following code to my “requirements.txt” file: flask_swagger_ui==3.36.0.

However this did not change anything and I still received the same error. I tried adding the module directly into the Dockerfile I created through this code but that did not work either:

RUN pip install flask_swagger_ui

Doing one or both of these things results in 502 Gateway error. I have tried to add several other modules to my application Like Pandas and Sklearn but they result in the same error. I can NOT make any changes to my application without getting Bad Gateway.

To figure out what is wrong, I removed all the changes I had made and got it back to where the only dependency is Flask 2.0.1 in my “requiements.txt”. After testing that the Docker is running fine, In a state of confusion, I removed “start.sh”, “Dockerfile” and “requirements.txt” and put them in trash bin and restarted Docker.

To my bewilderment, The Docker was working fine! with all the files mentioned above in the trash bin! Since at this point now I was completely lost, I added all the dependencies back again to see if it works this time and got stuck with the same 502 Error and the Logs showed the same issue.

My question then is:

  1. How do I add a dependency to my application?
  2. How on Earth is my Docker container still running after 3 required files in trash bin? I stopped and restarted Docker again, As far as I know, It should not have worked.
  3. Removing “Flask 2.0.1” from the requirements.txt file while it was in my directory and restarting my docker did not affect my Docker application at all and it was running fine. What is happening?

Here is my Dockerfile:

FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine3.7
RUN apk --update add bash nano
RUN pip install pandas flask_swagger_ui
ENV STATIC_URL /static
ENV STATIC_PATH /home/faraz/python_docker/TestApp/app/static
COPY ./requirements.txt /home/faraz/python_docker/TestApp/requirements.txt
RUN pip install -r requirements.txt

and here is my requirements.txt:

Flask==2.0.1
flask_swagger_ui==3.36.0
pandas==1.2.4

Finally, my “start.sh”:

#!/bin/bash
app="docker.test"
docker build -t ${app} .
docker run -d -p 56733:80 \
  --name=${app} \
  -v $PWD:/app ${app}

I had posted another question when I was building my API and the link below will take you to it:Method Not Allowed The method is not allowed for the requested URL. 405 Error

Here is the Github Repository: