After 2 days of tiresome work I found the proper solution. My domain got 2 files when implemented ssl or https. One is mydomain_com.crt file, another is private.key
I found these 2 files in my server's main directory. As I am using Apache, then I found these files in /etc/var/www/html folder.
I copied 2 files as follows:
copied the license from mydomain_com.crt file and paste in a text file then renamed it certificate.pem
copied the license from private.key and paste in a text file then renamed it privateKey.pem
Then I used my domain's default ssl certificate into my Flask app like this:
import ssl
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.load_cert_chain('certificate.pem', 'privateKey.pem')
.
.
.
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', ssl_context=ctx)
And exposed the 2 ports in my Dockerfile like this :
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "app.py" ]
EXPOSE 80
EXPOSE 443
After restart, my Dockerized Flask app now working with my domain's default ssl certificate and serving the APIs correctly.
Example : https:mydomain.com:5000/getUsers
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…