werkzeug: 0.15.0 causes OSError: [Errno 8] Exec format error: in Docker for Windows
The new 0.15.0 does not run in Docker for Windows. Have not tried Docker on other platforms.
Minimal example with Flask.
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, world!'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Dockerfile
FROM python:3-onbuild
COPY . /usr/src/app
CMD ["python", "app.py"]
requirements.txt
# Werkzeug==0.14.1
Flask
Run docker build -t flask_test . and then docker run flask_test.
Error in container:
λ docker run flask_test
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "app.py", line 11, in <module>
app.run(debug=True, host='0.0.0.0')
File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 988, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
sys.exit(reloader.restart_with_reloader())
File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ, close_fds=False)
File "/usr/local/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/local/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/usr/src/app/app.py
Uncomment the first line in requirements.txt and it runs properly after rebuild.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (5 by maintainers)
Commits related to this issue
- Add shebang to make maapapp.py to make it werkzeug-compatible: https://github.com/pallets/werkzeug/issues/1482#issuecomment-475181497 — committed to MAAP-Project/maap-api-nasa by deleted user 5 years ago
Did the same tutorial and found the same issue. This fixed it for me.
I added the following shebang to the top of my
app.pyscript#!/usr/local/bin/python3Which then caused permission issues. I then added the following to my
Dockerfilebefore the CMDRUN chmod 644 app.pyUse the
flask runcommand.As I said, I agree with the main logic here. I disagree with the way the error is dealt with as well as the fact that the error message is unintelligible unless you know the know the technical details or read the code. It should at least be documented in the changelog.
If you mark a script as executable, you should add a corresponding interpreter comment to the top. You can use a tool like pre-commit’s
check-executables-have-shebangshook to enforce that.If you don’t intend for a script to be directly executable, and want to require
python script.pyinstead, then you should not mark it executable.Also, if I explicitly run
python app.py, then the subprocess should not make any assumption and change the way I run the application. i.e: working with a virtual machine with shared folder makes every files executable by default.