Multi stage builds do indeed seem much better, thanks
Regarding writing bytecode - this slows down the first load of a file, in exchange for speeding up subsequent loads of a file. It has no effect on runtime speed. Given that python code is only loaded once when a Docker image is run, it is better to disable this.
2. It's not perfect to include gcc; it's certainly OK, but it's possible to do better with multi-stage builds, as someone else commented.
3. You probably want PYTHONFAULTHANDLER=1 so segfaults gets tracebacks.
Etc..
Going from "it works" to "it's production-ready" is quite a bit of effort!