Skip to content

Allow compose to show container shutdown logs. With an alternative UI. #12918

Description

@robinhickmann

Description

Containers printing logs on shutdown don't get displayed.

Steps To Reproduce

Example code

package main

import (
    "fmt"
    "os"
    "os/signal"
    "syscall"
)

func main() {
    sigChan := make(chan os.Signal, 1)
    signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

    fmt.Println("Hello, World!")

    <-sigChan

    fmt.Println("Goodbye, World!")
}

Example Dockerfile

FROM golang:alpine

WORKDIR /app

COPY . .

RUN go build -o hello .

CMD ["./hello"]

Example compose.yml

services:
  hello:
    build: .
  1. Run docker compose up --build.

  2. Press CTRL + C to gracefully shutdown all the services.

  3. Notice how you won't see the "Goodbye, World!" log but if you run docker compose logs hello, you'll see the log.

Compose Version

Docker Compose version v2.36.2

Docker Environment

Client: Docker Engine - Community
 Version:    28.2.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.24.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.36.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 25
  Running: 0
  Paused: 0
  Stopped: 25
 Images: 73
 Server Version: 28.2.2
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  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
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.14.9-300.fc42.x86_64
 Operating System: Fedora Linux 42 (Workstation Edition)
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.26GiB
 Name: nzxt-pc
 ID: 243ae51b-a1fb-4b73-a42d-ef8cb1420620
 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?

I assume it's just detaching too early, causing it not to print the logs, but I don't know if this is intended behavior. To me, this seems like it should print the logs on shutdown.

Activity

  1. changed the title [-][BUG] Deataches to logs too early on shutdown[/-] [+][BUG] Deattaches to logs too early on shutdown[/+] on Jun 8, 2025
  2. changed the title [-][BUG] Deattaches to logs too early on shutdown[/-] [+][BUG] Detaches to logs too early on shutdown[/+] on Jun 8, 2025
  3. changed the title [-][BUG] Detaches to logs too early on shutdown[/-] [+][BUG] Detaches from logs too early on shutdown[/+] on Jun 8, 2025
  4. robinhickmann commented on Jun 8, 2025

    @robinhickmann
    Author

    Forgot to mention, I tested this using docker run, and when I shutdown the container, it does actually print the shutdown logs.

  5. added a commit that references this issue on Jun 9, 2025
    1eb0705
  6. ndeloof commented on Jun 10, 2025

    @ndeloof
    Contributor

    This is something I considered in the past but not a trivial one: as we show progress UI for the stop sequence, we can't mix with logs. Would need to create an alternative progress UI that would not lock access to the terminal. Could show status change events as single line messages + a one-line progress state bar on the bottom (same as menu). Not that simple 😅

  7. robinhickmann commented on Jun 10, 2025

    @robinhickmann
    Author

    This is something I considered in the past but not a trivial one: as we show progress UI for the stop sequence, we can't mix with logs. Would need to create an alternative progress UI that would not lock access to the terminal. Could show status change events as single line messages + a one-line progress state bar on the bottom (same as menu). Not that simple 😅

    Yeah, I understand, that's fair. Hopefully this could get added this in the future, as I feel like it's a feature worth having.

  8. changed the title [-][BUG] Detaches from logs too early on shutdown[/-] [+]Allow compose to show container shutdown logs. With an alternative UI.[/+] on Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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