我有一个在我的dockerfile中启动的Python(2.7)应用程序:
CMD ["python","main.py"]
main.py在启动时会打印一些字符串,然后进入循环:
print "App started"
while True:
time.sleep(1)
只要我使用-it标志启动容器,一切都会按预期进行:
$ docker run --name=myapp -it myappimage
> App started
我稍后可以通过日志看到相同的输出:
$ docker logs myapp
> App started
如果我尝试使用-d标志运行相同的容器,则该容器似乎正常启动,但看不到任何输出:
$ docker run --name=myapp -d myappimage
> b82db1120fee5f92c80000f30f6bdc84e068bafa32738ab7adb47e641b19b4d1
$ docker logs myapp
$ (empty)
但是容器似乎仍在运行;
$ docker ps
Container Status ...
myapp up 4 minutes ...
附件也不显示任何内容:
$ docker attach --sig-proxy=false myapp
(working, no output)
任何想法出什么事了吗?在后台运行时,“打印”行为是否有所不同?
Docker版本:
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.2
Git commit (client): a8a31ef
OS/Arch (client): linux/arm
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.2
Git commit (server): a8a31ef