simon / Docker

Last active 1 month ago

docker.md Raw

docker

Build arm64 image on amd64 host

 docker buildx build --platform linux/arm64 -t glitchcrab/ubuntu-debug:latest --output=type=registry .

Run commands in container’s network namespace

  • get the container's ID from docker ps, then use it to get the PID:

pid=$(docker inspect -f '{{.State.Pid}}' ${container_id})

  • ensure the netns dir exists and then create the required symlink:
mkdir -p /var/run/netns/
ln -sfT /proc/<pid>/ns/net /var/run/netns/<container id>
  • run a command inside the netns:

ip netns exec <container id> ip a


Find largest container log files

find /var/lib/docker/containers \
    -name '*-json.log' \
    -printf '%s %p\n' \
| sort -nr \
| numfmt --to=iec

Check disk usage

docker system df