Container logs with docker compose like legacy docker-compose

When I run docker compose, it prints logs for creating the container but then just waits for the container to exit.

[+] Building 0.6s (26/26) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                         

[...building from cache log entries...]

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 1/0
 ⠿ Container docs-builder  Recreated                                                                                                                                                                                                                                                                                                                         0.1s
Attaching to docs-builder
docs-builder exited with code 2

When running the same command but with the legacy docker-compose instead of docker compose, it also prints the logs from the container

Building build-docs
[+] Building 0.3s (26/26) FINISHED
 => [internal] load build definition from Dockerfile      

[...building from cache log entries...]                                                                                                                                                                                                                                                                                                    

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Recreating docs-builder ... done
Attaching to docs-builder
docs-builder  | Running Sphinx v3.4.3

[...more useful logs from container...]   

docs-builder exited with code 2

Is there any way to get those container logs to show up while using the V2 compose command?

thanks,

Normally you should see the logs regardless of the compose version. But… here is my guess. Since I see you run Sphinx which is a Python app for generating documentations, and Docker Compose v1 was written in Python as well, that could be more compatible. In Python, when you run it in a container, you often need to set the

PYTHONUNBUFFERED=1

environment variable in the container to get the logs immediately. So I guess the logs were lost in the buffer but this is indeed just a guess. I had no problem with Compose v2 and logs.

No luck with PYTHONUNBUFFERED. My understanding is that if I needed to use PYTHONUNBUFFERED, the logs would still print but only show up when the container exits – but it’s been a while since I’ve had to mess with that.

Interestingly, you’re at least right that it’s not universal – other containers are printing as desired. Will try to determine what’s different.

Thanks