unable to stream container logs
See original GitHub issueUsing the following code, I’ve been unable to stream logs without the generator blocking infinitely:
import docker
base_url = 'unix://var/run/docker.sock'
client = docker.Client(base_url=base_url,
version='1.14',
timeout=10)
command = 'echo hello world'
container = client.create_container('ubuntu:14.04', command=command)
client.start(container)
log_stream = client.logs(container, stream=True)
for line in log_stream:
print(line)
but waiting for the container to complete and reading the logs without streaming works just fine. Am I consuming the output incorrectly, or is there another issue here?
I’m currently using Docker 1.2.0 on Arch, with Python 3.4.1.
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Why are my Amazon ECS container logs not delivered to ...
Your Amazon ECS container logs aren't delivered to CloudWatch Logs due to one or more of the following reasons: The awslogs log driver...
Read more >View container logs - Docker Documentation
The docker service logs command shows information logged by all containers participating in a service. The information that is logged and the format...
Read more >How to Live Tail Docker Logs - Papertrail
In Docker jargon, we refer to creating a continuous stream of log output as tailing logs. To tail the logs for our container,...
Read more >How to view Docker logs to troubleshoot containers
The only thing you'll need to view Docker container logs is Docker deployed to a machine. It doesn't matter what the platform is,...
Read more >Docker Log Collection Troubleshooting Guide - Datadog Docs
This status means that the Agent is unable to find a log file for a given container. To resolve this issue, check that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @kvchen, I found a way to fix this problem. In spite I’m creating a Django container, you just need to create a loop in the streaming process and print the log line like this:
It creates a streaming loop in order to print each request that comes to the container. The output goes to be:
Then, create some requests to the endpoint and it shows…
Hope it works for you. It works properly on my project DBMQ.
I ran up against this. I wonder is it the stream kwarg of run that is confusing people (it confused me). I would expect the following to be a non-blocking call and return a generator:
What I wanted was actually: