How to get the container log file using docker-py

2.6k Views Asked by At

As part of docker automation am trying to automate certain docker operation using python docker package. Well I have implemented the most of requirement successfully, But could not find an equivalent method for

docker logs <container-id>

My implementation:

import docker
client = docker.APIClient()
client.attach(container, stdout=True, stderr=True, stream=False, logs=True, demux=False)

However it does not give result what am expecting. Kindly help me to identify what is missing in the implementation. Thanks in advance for going through this question

#UPDATE

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)

Well I have replace my implementation with above one by referring to link. Although it does not work when tail option added. On adding the tail command it is showing blank without any error. Any hint on getting tailed results

0

There are 0 best solutions below