Flask, Gunicorn, Docker and Traefik
Working this out took 3 days to get the result below; the biggest issue faced is that there are SO MANY ways each solution can be configured and so MANY MANY ways these configurations can break the other.
Result
URL localhost:8080
This gives THREE routes on same server that will show the flask app.
URL: http://web2.localhost/web2/. Show a route to web2
URL: http://web2.localhost/web2/, Show web2 route within a subdomain
URL: http://localhost/. Default route
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
So here is how I got it working…
0. Install Docker Desktop, take the default settings; nothing special here
- Create a directory for the Docker Flask — Gunicorn app with the following files.
2. Create a directory for the Traefik container which will be a reverse proxy for the web app
3. Create a network in Docker for BOTH containers to connect to (THIS IS VERY IMPORTANT!)
docker network create backendweb
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
1…setup files
2…setup files
To run the project…
cd {directory of the files in dockerapp}
docker image build -t flask_docker .
Now you have the flask app, wrapped in gunicorn and in a docker container.
Run the container from the command line
docker-compose up
cd {directory of the files in reverseproxy}
docker-compose up
Thats it.
It should work now :-)