Allow to execute "flask shell" in the portal container without setting env variables
Recommended skills:
- Rough understanding of Docker, or
- Will to read some documentation and fiddle around.
Flask applications allow access to a Python shell with which Python code can be executed in the running application using the command flask shell
.
For this to work, the environment variable FLASK_APP
needs to be set to contain the name of the application to spawn a shell into.
As we run the Flask app inside docker, we first need to get inside the Docker container using:
sudo docker exec -it portal-app-1 bash
Then, we need to set the environment variable and launch the shell:
export FLASK_APP=portal
flask shell
This is annoying. It would be cooler to just execute:
sudo docker exec -it portal-app-1 flask shell
But that yields to the following error, because the environment variable FLASK_APP
is not set:
Usage: flask shell [OPTIONS]
Try 'flask shell --help' for help.
Error: Could not locate a Flask application. Use the 'flask --app' option, 'FLASK_APP' environment variable, or a 'wsgi.py' or 'app.py' file in the current directory.
It would be great if that could be fixed, preferably by editing the Dockerfile
somehow.
Maybe helpful resources
Edited by Jakob Moser