I'm trying to perform an automation using docker package of python. In that I tried to read the logs with tails with below code, But it is showing nothing.
import docker
z=docker.from_env()
dkg = z.containers.get('<container_id>').logs(stream = True, follow = False, tail =10)
while True:
line = next(dkg).decode("utf-8")
print(line)
It would be helpful if you could identify the missing item in my code. Thanks in Advance for going through the question
That code should work well.
The
follow=True
will keep waiting for more data; maybe that can help you.Also, be sure that the data is being written to stdout.
I suggest changing the loop like this:
That will avoid the
StopIteration
Exception.