compose icon indicating copy to clipboard operation
compose copied to clipboard

Compose fail to capture logs for a container on restart

Open ndeloof opened this issue 4 years ago • 7 comments

services:
  noop:
    image: ubuntu
    command: sleep 10
  test:
    image: ubuntu
    command: bash -c 'echo hello'
    restart: always

(see https://github.com/docker/compose/issues/8896 about the noop service)

expected behavior:

docker compose up show hello in a loop, only once per container run

compose v1 capture the whole container log, including previous logs

docker-compose-v1 up
Creating truc_test_1 ... done
Creating truc_noop_1 ... done
Attaching to truc_test_1, truc_noop_1
test_1  | hello
truc_test_1 exited with code 0
test_1  | hello
test_1  | hello
truc_test_1 exited with code 0
test_1  | hello
test_1  | hello
test_1  | hello
truc_test_1 exited with code 0
test_1  | hello
test_1  | hello
test_1  | hello
test_1  | hello

compose v2 don't include previous run logs (nice) but is missing the very first log of the restarting container (bad):

docker-compose up
[+] Running 2/2
 ⠿ Container truc_test_1  Recreated                                        0.1s
 ⠿ Container truc_noop_1  Recreated                                        0.1s
Attaching to truc-noop-1, truc-test-1
truc-test-1  | hello
truc-test-1 exited with code 0
truc-test-1 exited with code 0
truc-test-1 exited with code 0
truc-test-1 exited with code 0

This is probably the same issue reported on https://github.com/docker/compose/issues/8884

I tried using die event timestamp to limit logs with since filter, but the granularity is seconds and this failed

ndeloof avatar Nov 08 '21 06:11 ndeloof

@thaJeztah maybe you know some magic hook we could use here to only get the relevant "after container restarted" logs from history?

ndeloof avatar Nov 08 '21 08:11 ndeloof

Hmm.. no, I don't think there's such a concept in the API, as the logs are just considered "all logs since container creation" (but can be limited to a certain "size", depending on log-config for the container).

but the granularity is seconds and this failed

Having a quick look at the API docs for the events endpoint, I see it has timeNano field; or is the granularity on the filtering part?

thaJeztah avatar Nov 08 '21 10:11 thaJeztah

right, maybe timeNano, can't remember. When I tried using this is didn't helped

ndeloof avatar Nov 08 '21 11:11 ndeloof

Since: Only return logs since this time, as a UNIX timestamp

ndeloof avatar Nov 08 '21 11:11 ndeloof

Looking at the daemon code, it may actually be able to handle nanoseconds; https://github.com/moby/moby/blob/7b9275c0da707b030e62c96b679a976f31f929d3/daemon/logs.go#L75-L81

I'm guessing the intent was to only support unix timestamps, but the actual code supports timestamps with nanoseconds 🤔 https://github.com/moby/moby/commit/e8d9a61f4c9e1f3cfdf1c889c541c9dc72a4bb40

thaJeztah avatar Nov 08 '21 15:11 thaJeztah

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 12 '22 17:06 stale[bot]

This issue has been automatically closed because it had not recent activity during the stale period.

stale[bot] avatar Aug 01 '22 00:08 stale[bot]

This issue has been automatically closed because it had not recent activity during the stale period.

stale[bot] avatar Aug 13 '22 11:08 stale[bot]