2016-08-23 10 views
10

私はFlask/Celery/Redisサービスをスポーンするのにdocker-composeを使用しようとしています。ここでセロリとフラスコを同じドッカーで作っています

は私docker-compose.ymlです:私はこのdocker-composeを実行すると、予想通り

flask: 
    build: . 
    command: "python3 app.py" 
    ports: 
     - '5000:5000' 
    links: 
     - redis 
    volumes: 
     - .:/usr/src/app:ro 

celery: 
    build: . 
    command: "celery -A app.celery worker --loglevel=info" 
    volumes: 
     - .:/usr/src/app:ro 

redis: 
    image: redis 
    ports: 
     - '6379:6379' 

、フラスコやRedisの両方が細かいと機能を開始します。セロリについては、Dockerはflaskcelery_celery_1 exited with code 1を報告し、他の情報はありません。

私がDockerなしで3つのサービスを実行し、celery -A app.celery worker --loglevel=infoでCeleryを起動すると、私のアプリはうまく機能します。

いくつかのより多くの情報は、必要に応じて:

Dockerfile:(この画像は、同様に、ビルドにrequirements.txtをインストールします)

FROM python:3.5-onbuild 
EXPOSE 5000 

requirements.txt:

flask==0.11.1 
celery==3.1.23 

docker-compose up出力:

Starting flaskcelery_celery_1 
Starting flaskcelery_redis_1 
Starting flaskcelery_flask_1 
Attaching to flaskcelery_celery_1, flaskcelery_redis_1, flaskcelery_flask_1 
redis_1 |     _._             
redis_1 |   _.-``__ ''-._            
redis_1 |  _.-`` `. `_. ''-._   Redis 3.2.3 (00000000/0) 64 bit 
redis_1 | .-`` .-```. ```\/ _.,_ ''-._         
redis_1 | ( '  ,  .-` | `, )  Running in standalone mode 
redis_1 | |`-._`-...-` __...-.``-._|'` _.-'|  Port: 6379 
redis_1 | | `-._ `._ / _.-' |  PID: 1 
redis_1 | `-._ `-._ `-./ _.-' _.-'         
redis_1 | |`-._`-._ `-.__.-' _.-'_.-'|         
redis_1 | | `-._`-._  _.-'_.-' |   http://redis.io   
redis_1 | `-._ `-._`-.__.-'_.-' _.-'         
redis_1 | |`-._`-._ `-.__.-' _.-'_.-'|         
redis_1 | | `-._`-._  _.-'_.-' |         
redis_1 | `-._ `-._`-.__.-'_.-' _.-'         
redis_1 |  `-._ `-.__.-' _.-'          
redis_1 |   `-._  _.-'           
redis_1 |    `-.__.-'            
redis_1 | 
redis_1 | 1:M 23 Aug 10:23:08.409 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 
redis_1 | 1:M 23 Aug 10:23:08.409 # Server started, Redis version 3.2.3 
redis_1 | 1:M 23 Aug 10:23:08.409 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 
redis_1 | 1:M 23 Aug 10:23:08.409 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 
redis_1 | 1:M 23 Aug 10:23:08.409 * The server is now ready to accept connections on port 6379 
flaskcelery_celery_1 exited with code 1 
flask_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 
flask_1 | * Restarting with stat 
flask_1 | * Debugger is active! 
flask_1 | * Debugger pin code: 196-119-737 

答えて

9

私の問題を解決しました。私は最終的に私がドッカー画像上でコマンドプロンプトを得ることができます考え出した:そして、コンテナ内celeryを実行しようとして

docker build -t <image name> . 
docker run -it <image name> /bin/bash 

は、問題を明らかにした:

[email protected]:/usr/src/app# celery -A app.celery worker --loglevel=info 
Running a worker with superuser privileges when the 
worker accepts messages serialized with pickle is a very bad idea! 

If you really want to continue then you have to set the C_FORCE_ROOT 
environment variable (but please think about this before you do). 

User information: uid=0 euid=0 gid=0 egid=0 

ドッカーは通常rootとして実行され、セロリのdoesnセキュリティ上の理由からrootとして実行するのが好きではありません(私はあなたがpickle deserializationでコードを実行できると信じています)。より安全な解決策は、nobodyとして実行するようにceleryコンテナを設定することでした。作業中docker-compose.yml

flask: 
    build: . 
    command: "python3 app.py" 
    ports: 
     - '5000:5000' 
    links: 
     - redis 
     - celery 
    volumes: 
     - .:/usr/src/app:ro 

celery: 
    build: . 
    command: "celery -A app.celery worker --loglevel=info" 
    user: nobody 
    links: 
     - redis 
    volumes: 
     - .:/usr/src/app:ro 

redis: 
    image: redis 
    ports: 
     - '6379:6379' 
関連する問題