User Tools

Site Tools


apps:docker:troubleshooting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
apps:docker:troubleshooting [2025-02-01 20:10] – add info to disk usage Manuel Freiapps:docker:troubleshooting [2025-02-04 17:09] (current) – add xargs data Manuel Frei
Line 54: Line 54:
 container_pid="$(docker inspect --format "{{ .State.Pid }}" "${container_id}")" container_pid="$(docker inspect --format "{{ .State.Pid }}" "${container_id}")"
 nsenter -n -t "${container_pid}" tcpdump -nn -i eth0 nsenter -n -t "${container_pid}" tcpdump -nn -i eth0
 +</code>
 +
 +===== Logs =====
 +
 +==== Add Local Timestamp to Container Logs ====
 +
 +If a container is logging without a timestamp or with an unknown time zone, you can add a timestamp while watching the logs.
 +<code bash>
 +docker logs mycontainer -n 0 -f | xargs -IL date +'[%Y-%m-%dT%H:%M:%S%:z] L'
 +</code>
 +
 +In case you want to catch the stderr logs, too
 +<code bash>
 +docker logs mycontainer -n 0 -f 2>&1 | xargs -IL date +'[%Y-%m-%dT%H:%M:%S%:z] L'
 +</code>
 +
 +<code - Example>
 +root@server:~# docker logs mycontainer -n 0 -f 2>&1 | xargs -IL date +'[%Y-%m-%dT%H:%M:%S%:z] L'
 +[2025-02-04T16:55:01+01:00] 2025-02-04T15:55:01+0000 INFO main.py:24 send request for url http://server/ping.
 +[2025-02-04T16:55:01+01:00] 2025-02-04T15:55:01+0000 INFO main.py:29 Received answer with HTTP status code 200 and content: GET: pong
 +[2025-02-04T16:55:03+01:00] 2025-02-04T15:55:03+0000 INFO main.py:24 send request for url http://server/ping.
 +[2025-02-04T16:55:03+01:00] 2025-02-04T15:55:03+0000 INFO main.py:29 Received answer with HTTP status code 200 and content: GET: pong
 +[2025-02-04T16:55:05+01:00] 2025-02-04T15:55:05+0000 INFO main.py:24 send request for url http://server/ping.
 +[2025-02-04T16:55:05+01:00] 2025-02-04T15:55:05+0000 INFO main.py:29 Received answer with HTTP status code 200 and content: GET: pong
 </code> </code>
  
apps/docker/troubleshooting.txt · Last modified: 2025-02-04 17:09 by Manuel Frei