2年ぶりにdockerからflaskアプリケーションを立ち上げると色々エラー出た
その顛末について色々記載する
Pipインストール時にエラー発生
Pipインストール時にエラーが発生した
Collecting MarkupSafe==1.0
Downloading MarkupSafe-1.0.tar.gz (14 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bbqn1izc/MarkupSafe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bbqn1izc/MarkupSafe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1vlq3685
cwd: /tmp/pip-install-bbqn1izc/MarkupSafe/
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-bbqn1izc/MarkupSafe/setup.py", line 6, in <module>
from setuptools import setup, Extension, Feature
ImportError: cannot import name 'Feature'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
とりあえず、MarkupSafeにバージョンに問題がありそうなので、最新版が適用されるようrequirements.txtからバージョン指定を外した
サーバ起動時にエラー発生 その1
サーバ起動時に
web_1 | Traceback (most recent call last):
web_1 | File "app.py", line 5, in <module>
web_1 | from werkzeug import ImmutableDict
web_1 | ImportError: cannot import name 'ImmutableDict'
pythonweb_web_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
Stopping pythonweb_redis_1 ... done
というエラーが出る
ImmutableDictがロードできないみたいなエラーが出ているが、なぜ、そうなったのかはログからは全くわからない
仕方がないのでネットを色々調べてみたらWerkzeugに最新版を適用するとこのエラーが出るらしい
(なんでやねん)
0.15を適用するといいみたいなことが書いてあったので、requirements.txtを修正した
サーバ起動時にエラー発生 その2
再度、docker-compose upでサーバーを起動したが、またまたエラーが発生!
マジで勘弁してほしい・・・
web_1 | Traceback (most recent call last):
web_1 | File "app.py", line 55, in <module>
web_1 | app.run(host='0.0.0.0',debug=True)
web_1 | File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 990, in run
web_1 | run_simple(host, port, self, **options)
web_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 988, in run_simple
web_1 | run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
web_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
web_1 | sys.exit(reloader.restart_with_reloader())
web_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
web_1 | exit_code = subprocess.call(args, env=new_environ, close_fds=False)
web_1 | File "/usr/local/lib/python3.6/subprocess.py", line 287, in call
web_1 | with Popen(*popenargs, **kwargs) as p:
web_1 | File "/usr/local/lib/python3.6/subprocess.py", line 729, in __init__
web_1 | restore_signals, start_new_session)
web_1 | File "/usr/local/lib/python3.6/subprocess.py", line 1364, in _execute_child
web_1 | raise child_exception_type(errno_num, err_msg, err_filename)
web_1 | OSError: [Errno 8] Exec format error: '/myapp/app.py'
pythonweb_web_1 exited with code 1
ログから見るに、app.pyに何か設定が足りないようなことはわかるが具体的な内容はぱっとみわからない
ネットで色々調べてみると、pythonの実行環境のパスをコメントで指定してあげる必要があるとのこと
app.pyに
#! /usr/bin/env python
を追記してサーバー起動したら、無事、Webページを表示することができたよ
追記
今回の修正差分をGithubにあげました
https://github.com/triple4649/pythonweb/commit/6322f563aaeacb3574424ade8aca76c22b7c6ab1#diff-b4ef698db8ca845e5845c4618278f29a