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
Next revision
Previous revision
apps:docker:troubleshooting [2025-02-01 19:39] – add disk usage snippets Manuel Freiapps:docker:troubleshooting [2025-02-04 17:09] (current) – add xargs data Manuel Frei
Line 1: Line 1:
 ====== Docker Troubleshooting ====== ====== Docker Troubleshooting ======
  
-===== Disk Usage =====+===== Disk Usage (MergeDir) ===== 
 + 
 +If you run out of disk usage and it's not the data from your volumes, maybe a container is writing data to the overlay file system. This data is placed in the merge directory. Try the following snippets to show the size of the merge directory for all the containers. 
  
 <code bash> <code bash>
Line 16: Line 18:
 </code> </code>
  
 +This is how the output could be displayed.
 <code - Example> <code - Example>
 root@server:~# while read -r name mergedir _; do size="$([ -d "${mergedir}" ] && du -s "${mergedir}" | cut -f 1)"; size_hr="$(awk -v s="${size:=0}" 'BEGIN { printf "%.2f\n", s/1024 }')"; echo "${name} ${mergedir} ${size:=0} ${size_hr}"; done <<< "$(docker inspect $(docker ps -qa) |  jq -r 'map([.Name, .GraphDriver.Data.MergedDir]) | .[] | "\(.[0])\t\(.[1])"')" | sort -nk3 | awk 'BEGIN{ print "NAME","MERGE_DIR","SIZE_B","SIZE_MB" } { print $0 }' | column -t root@server:~# while read -r name mergedir _; do size="$([ -d "${mergedir}" ] && du -s "${mergedir}" | cut -f 1)"; size_hr="$(awk -v s="${size:=0}" 'BEGIN { printf "%.2f\n", s/1024 }')"; echo "${name} ${mergedir} ${size:=0} ${size_hr}"; done <<< "$(docker inspect $(docker ps -qa) |  jq -r 'map([.Name, .GraphDriver.Data.MergedDir]) | .[] | "\(.[0])\t\(.[1])"')" | sort -nk3 | awk 'BEGIN{ print "NAME","MERGE_DIR","SIZE_B","SIZE_MB" } { print $0 }' | column -t
Line 52: 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.1738435167.txt.gz · Last modified: 2025-02-01 19:39 by Manuel Frei