从Docker容器获取控制台输出

时间:2015-10-12 14:13:30

标签: amazon-ec2 docker amazon-ecs

我使用python instaled和python应用程序构建一个图像。我的python应用程序是一个hello world,只需在屏幕上打印“Hello World”。 Dockerfile:

FROM python:2-onbuild
CMD ["python", "./helloworld.py"]

在控制台中执行:

docker run xxx/zzz

我可以看到Hello World输出。现在我尝试使用ECS的任务执行相同的应用程序。我已经把它拉到了Docker Hub。 如何查看输出问候世界?无论如何你看到我的容器运行正常吗?

5 个答案:

答案 0 :(得分:7)

docker logs <container id>将显示conatiner运行的所有输出。如果您在ecs上运行它,您可能需要为运行容器的主机设置DOCKER_HOST=tcp://ip:port

答案 1 :(得分:0)

您可以登录容器实例,例如在那里/opt/gmock-1.7.0/include/gmock/gmock-more-actions.h:80: instantiated from ‘Result testing::internal::InvokeMethodAction<Class, MethodPtr>::Perform(const ArgumentTuple&) const [with Result = void, ArgumentTuple = std::tuple<const std::string&>, Class = TemplateParser, MethodPtr = unsigned int (TemplateParser::*)()]’ /opt/gmock-1.7.0/include/gmock/gmock-actions.h:371: instantiated from ‘typename testing::internal::Function<F>::Result testing::PolymorphicAction<Impl>::MonomorphicImpl<F>::Perform(const typename testing::internal::Function<F>::ArgumentTuple&) [with F = void(const std::string&), Impl = testing::internal::InvokeMethodAction<TemplateParser, unsigned int (TemplateParser::*)()>]’ test/src/ParserTest.cpp:315: instantiated from here /opt/gmock-1.7.0/include/gmock/gmock-generated-actions.h:83: error: too many arguments to function /opt/gmock-1.7.0/include/gmock/gmock-generated-actions.h:83: error: return-statement with a value, in function returning 'void' make: *** [test/obj/ParserTest.o] Error 1

本指南介绍如何连接容器实例:

http://docs.aws.amazon.com/AmazonECS/latest/developerguide/troubleshooting.html#instance-connect

答案 2 :(得分:0)

我们可以使用

docker logs <container name>

答案 3 :(得分:0)

要实时查看Docker容器的日志,请使用以下命令:

docker logs -f <CONTAINER>

-f--follow选项将显示实时日志输出,此外,如果容器停止,它将获取其日志。

答案 4 :(得分:0)

也许除了跟踪日志外,最好通过以下方式进入容器:

docker exec -it CONTAINER_ID /bin/sh

并从内部调查您的过程。