Search code examples
pythondockerimportbytecode

Running python in read-only Docker container


I have a web app that I want to run using Docker container with nginx. As I know, it is suggested that I use read-only container for security purposes, but when I run my app on local machine, it always generates __pycache__ folder. Will it be a problem when running in read-only environment? If yes, how to solve it?


Solution

  • You can start Python with the -Bargument:

    python -B myscript.py
    

    This turns off writing .pyc and .pyo files when you import .py files.

    Alternatively, you set and environmental variable:

    PYTHONDONTWRITEBYTECODE=x