moby / moby/moby

`docker logs -t` needs to strip carriage return character to show timestamp

Open
#49,076 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/0-triage
Dominant language
Go
Stars
72.1k
Forks
19.2k
Avg merge
1d 17h
Merged PRs (30d)
164

Description

Description

docker logs -t should prefix every log line with a timestamp like 2024-12-12T10:47:47.310209758Z.

When the container is using \n\r at the end of a log line (or \r at beginning), then the timestamp is overwritten and not shown.

2024-12-12T11:25:38.363477610Z There are only two hard things in computer science:
cache invalidation and naming things.
2024-12-12T11:25:38.363527859Z

docker logs should probably strip the /r, at least when used with -t option, maybe just on Linux.

The issue happens for example with containers based on mcr.microsoft.com/mssql/server:2022-latest image on Linux.

See discussion on Docker Community Forum.

Reproduce
docker run -d --name t1 bash echo -e "There are only two hard things in computer science: \ncache invalidation and naming things.\n"
docker logs -t t1
docker rm t1

docker run -d --name t2 bash echo -e "There are only two hard things in computer science: \r\ncache invalidation and naming things.\r\n"
docker logs -t t2
docker rm t2

docker run -d --name t3 bash echo -e "There are only two hard things in computer science: \n\rcache invalidation and naming things.\n\r"
docker logs -t t3
docker rm t3

outputs

2024-12-12T11:25:37.492133962Z There are only two hard things in computer science:
2024-12-12T11:25:37.492317272Z cache invalidation and naming things.
2024-12-12T11:25:37.492330714Z

2024-12-12T11:25:37.932053082Z There are only two hard things in computer science:
2024-12-12T11:25:37.932101138Z cache invalidation and naming things.
2024-12-12T11:25:37.932106578Z

2024-12-12T11:25:38.363477610Z There are only two hard things in computer science:
cache invalidation and naming things.
2024-12-12T11:25:38.363527859Z

The last example has an overwritten timestamp

Expected behavior

The timestamp should always be shown, irrespectively of the log line content.

docker version
# docker version
Client: Docker Engine - Community
 Version:           27.4.0
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        bde2b89
 Built:             Sat Dec  7 10:38:55 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.4.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       92a8393
  Built:            Sat Dec  7 10:38:55 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.24
  GitCommit:        88bf19b2105c8b17560993bee28a01ddc2f97182
 runc:
  Version:          1.2.2
  GitCommit:        v1.2.2-0-g7cb3632
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
docker info
# docker info
Client: Docker Engine - Community
 Version:    27.4.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.19.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.31.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 19
  Running: 16
  Paused: 0
  Stopped: 3
 Images: 52
 Server Version: 27.4.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 88bf19b2105c8b17560993bee28a01ddc2f97182
 runc version: v1.2.2-0-g7cb3632
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-50-generic
 Operating System: Ubuntu 24.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.25GiB
 Name: myhost
 ID: d0b46f47-c57e-4b70-bdfe-39a9f8e01234
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Additional Info

No response

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 by running the three reproduction commands in the issue and inspect the docker logs output handling in the Moby repository. The change is done when timestamps remain visible for log lines containing carriage returns, with coverage for the demonstrated cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.