Skip to content

[BUG] ANSI escape color formatting lost on multiple lines in logs #12789

@ras0q

Description

@ras0q

Description

When a service outputs text with ANSI escape codes for color formatting across multiple lines, docker compose logs only preserves the color for the first line.
Subsequent lines are displayed without the indended color.

Expected Actual
Image Image

Steps To Reproduce

Write the following code and execute docker compose up

# compose.yaml
services:
  app:
    image: bash
    command: echo -e "\\e[31m This line is RED.\\n This line is also RED.\\n This span is ... \\e[34m BLUE."

Compose Version

$ docker compose version
Docker Compose version v2.23.3

Docker Environment

$ docker info
Client: Docker Engine - Community
 Version:    28.0.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.21.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.3
    Path:     /home/ras/.docker/cli-plugins/docker-compose

Server:
 Containers: 101
  Running: 0
  Paused: 0
  Stopped: 101
 Images: 111
 Server Version: 28.0.1
 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: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc version: v1.2.4-0-g6c52b3f
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.648GiB
 Name: asymp
 ID: 80909571-03a9-44bc-9158-3ca493dc5171
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions