docker / docker/docker-py

Container log return a single character instead line

Open
#2,913 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I try to get container logs using stream but instead of getting a line every time I get a single character
For example:
If the line in log is: 172.17.0.1 - - [17 / Nov / 2021: 14: 54: 05 +0000] "GET / HTTP / 1.1" 304 0 "-"

So I get in output 1 and in the next log I get the next character 7

Here is my python code:

container_logs = Sdk.docker_client.logs(container=containerid,
                                            stdout=True,
                                            stream=True)
while True:
        try:
            log = next(container_logs).decode("utf-8")
            socketio.emit('stream_logs_response', {'log': log, 'containerid':containerid}, to=sessionid)
            socketio.sleep(0)
       except StopIteration:
            socketio.emit('stream_logs_response', {'log': 'CONTAINER NOT RUNNING','containerid':containerid }, to=room)
            break

what am I missing here?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the docker_client.logs call and the Python loop shown in the issue, then review how streamed container-log values are returned. Reproduce the behavior with the example log and determine whether the returned chunks or the iteration boundary match the expected lines; done means the cause and an appropriate correction are covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.