Compose fail to capture logs for a container on restart
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
@thaJeztah maybe you know some magic hook we could use here to only get the relevant "after container restarted" logs from history?
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?
right, maybe timeNano, can't remember. When I tried using this is didn't helped
Since: Only return logs since this time, as a UNIX timestamp
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
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.
This issue has been automatically closed because it had not recent activity during the stale period.
This issue has been automatically closed because it had not recent activity during the stale period.