gunicorn在使用docker-compose run而不是docker-compose时调用

时间:2016-10-20 17:00:59

标签: python flask docker-compose gunicorn

我正在尝试在docker-compose中启动一个烧瓶应用程序。当我按如下方式运行时:

docker-compose run web /usr/local/bin/gunicorn restml.app:app -b :8000

gunicorn启动正常但我在docker-compose.yml

添加以下行时
command: /usr/local/bin/gunicorn restml.app:app -b :8000 --error-logfile - --log-level DEBUG

我得到了

web_1    | Traceback (most recent call last):
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
web_1    |     worker.init_process()
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
web_1    |     self.load_wsgi()
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
web_1    |     self.wsgi = self.app.wsgi()
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
web_1    |     self.callable = self.load()
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
web_1    |     return self.load_wsgiapp()
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
web_1    |     return util.import_app(self.app_uri)
web_1    |   File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 357, in import_app
web_1    |     __import__(module)
web_1    | ImportError: No module named 'restml'

文件结构为:

web
|-> Dockerfile
|-> requirements.txt
\-> restml
    \->app.py

我的app.py

from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return 'Index Page'


@app.route('/hello')
def hello():
    return 'Hello, World'

if __name__ == '__main__':
    app.run()

web的{​​{1}}条目是

docker-compose.yml

当我这样做时

web:
  build: ./web
  expose:
    - "8000"
  volumes:
    - /usr/src/app/
  env_file: .env
  environment:
     FLASK_DEBUG: 'true'
  command: /usr/local/bin/gunicorn restml.app:app -b :8000 --error-logfile - --log-level DEBUG

我得到了

docker-compose run web

所以它似乎比其他任何东西都更[2016-10-20 17:20:22 +0000] [1] [INFO] Starting gunicorn 19.6.0 [2016-10-20 17:20:22 +0000] [1] [DEBUG] Arbiter booted [2016-10-20 17:20:22 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1) [2016-10-20 17:20:22 +0000] [1] [INFO] Using worker: sync [2016-10-20 17:20:22 +0000] [7] [INFO] Booting worker with pid: 7 [2016-10-20 17:20:22 +0000] [1] [DEBUG] 1 workers

有人可以解释我如何解决这个问题吗?

其他信息

当我运行docker-compose时,我明白了,

docker-compose run web ls

当我运行Dockerfile requirements.txt restml 时,我明白了,

docker-compose run web ls restml

所有文件均为模式0644,文件为0755。

1 个答案:

答案 0 :(得分:0)

一些死容器仍然在后台运行。我删除了所有重新启动的内容,现在一切正常。

我使用

删除了它们
docker ps --all |  grep restml | cut -c138- | xargs docker rm