Skip to content

Docker tips

images

Remove all dangling images

docker image prune

Prompt

PS1='🐳  \[\033[1;36m\]\h \[\033[1;34m\]\W\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'

alt text


Mount tmpfs

1
2
3
4
docker run -it --rm  \
--mount type=tmpfs,destination=/mnt/ramdisk,tmpfs-size=64m,tmpfs-mode=1777 \
ubuntu:22.04 \
/bin/bash
check mount
1
2
3
df -h /mnt/ramdisk
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            64M     0   64M   0% /mnt/ramdisk

using compose

1
2
3
4
5
6
7
8
services:
  app:
    image: ubuntu:22.04
    command: bash
    tmpfs:
      - /mnt/ramdisk:size=64m,mode=1777
    stdin_open: true
    tty: true
run
docker compose -f tmpfs.yaml up -d
shell
docker exec -it code-app-1 /bin/bash
check mount
1
2
3
df -h /mnt/ramdisk
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            64M     0   64M   0% /mnt/ramdisk

Devices

Demo: share pixhawk device with docker

host
1
2
3
4
5
6
dmesg

usb 3-4.1.5.4: Product: CubeOrange
usb 3-4.1.5.4: Manufacturer: Hex/ProfiCNC
usb 3-4.1.5.4: SerialNumber: 1F0048001451303039333335
cdc_acm 3-4.1.5.4:1.0: ttyACM0: USB ACM device
host
ll /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Jul 11 07:19 /dev/ttyACM0
add to compose
1
2
3
4
5
6
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    group_add:
      - dialout
    device_cgroup_rules:
      - 'c 166:* rmw'

Demo: share by name

1
2
3
ll /dev/serial/by-id/
#
lrwxrwxrwx 1 root root 13 Jul 12 12:12 usb-ArduPilot_fmuv2_430032000551353532333634-if00 -> ../../ttyACM0
compose
1
2
3
4
5
6
7
devices:
    - /dev/serial/by-id/usb-ArduPilot_fmuv2_430032000551353532333634-if00:/dev/ttyPIXHawk
  group_add:
    - dialout
  device_cgroup_rules:
    - 'c 166:* rmw'
  restart: