docker在执行time.sleep(1)时在python循环中调用

通过使用docker-composepython:2.7 ,它仅while 1单独执行while 1循环和time.sleep(1)时正常运行。

但是当它们一起执行的时候会发生什么。

这是docker版本和我的mac上的文件内容

 tmp docker -v Docker version 1.12.5, build 7392c3b tmp cat docker-compose.yml version: '2' services: test: image: python:2.7 command: [python, -c, "print 0\nwhile 1:\n\tprint 1\n\tbreak"] tmp docker-compose up Creating network "tmp_default" with the default driver Creating tmp_test_1 Attaching to tmp_test_1 test_1 | 0 test_1 | 1 tmp_test_1 exited with code 0 tmp cat docker-compose.yml version: '2' services: test: image: python:2.7 command: [python, -c, "print 0\nimport time\nprint time.sleep(1)"] tmp docker-compose up Recreating tmp_test_1 Attaching to tmp_test_1 test_1 | 0 test_1 | None tmp_test_1 exited with code 0 tmp cat docker-compose.yml version: '2' services: test: image: python:2.7 command: [python, -c, "print 0\nimport time\nwhile 1:\n\tprint time.sleep(1)"] tmp docker-compose up Recreating tmp_test_1 Attaching to tmp_test_1 

在这里它Stucks。

希望知道修理它的原因和方法,谢谢。

添加-u标志到python为了有无缓冲的标准输出:

 command: [python, -uc, "print 0\nimport time\nwhile 1:\n\tprint time.sleep(1)"]