simon / Docker

Last active 1 month ago

simon revised this gist 1 month ago · 13946e8

1 file changed, 52 insertions

docker.md (file created)
@@ -0,0 +1,52 @@
1 + # docker
2 +
3 + ### Build arm64 image on amd64 host
4 +
5 + ```javascript
6 + docker buildx build --platform linux/arm64 -t glitchcrab/ubuntu-debug:latest --output=type=registry .
7 + ```
8 +
9 +
10 + ---
11 +
12 + ### Run commands in container’s network namespace
13 +
14 + * get the container's ID from `docker ps`, then use it to get the PID:
15 +
16 + `pid=$(docker inspect -f '{{.State.Pid}}' ${container_id})`
17 +
18 + * ensure the netns dir exists and then create the required symlink:
19 +
20 + ```
21 + mkdir -p /var/run/netns/
22 + ln -sfT /proc/<pid>/ns/net /var/run/netns/<container id>
23 + ```
24 +
25 + * run a command inside the netns:
26 +
27 + `ip netns exec <container id> ip a`
28 +
29 +
30 + ---
31 +
32 + ### Find largest container log files
33 +
34 + ```javascript
35 + find /var/lib/docker/containers \
36 + -name '*-json.log' \
37 + -printf '%s %p\n' \
38 + | sort -nr \
39 + | numfmt --to=iec
40 + ```
41 +
42 +
43 + ***
44 +
45 + ### Check disk usage
46 +
47 + ```javascript
48 + docker system df
49 + ```
50 +
51 +
52 + ***