Docker

来自百合仙子's Wiki
跳转到导航 跳转到搜索

配置

/etc/docker/daemon.json

{
  "experimental": true,
  "iptables": false,
  "storage-driver": "btrfs",
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com"
  ]
}

有用的命令

内存限制

docker update -m 500m --restart unless-stopped fishroom-web

一些镜像的注意事项

archlinux/base

  • 执行 rm /usr/share/libalpm/hooks/package-cleanup.hook 否则它会清空包缓存
  • 使用参数 -v /var/cache/pacman/pkg:/var/cache/pacman/pkg 挂载 pacman 缓存目录

问题处理

Ctrl-P 不立即生效

这是由于 docker 命令行默认使用 Ctrl-P Ctrl-Q 来 detach。通过配置文件 ~/.docker/config.json 可以更改此键序列:[1]

{
  "detachKeys": "ctrl-z,z"
}

内部原理

文件系统的位置

容器位于 containers/<ID> 下。容器使用的根文件系统由 layer 构成,在使用 btrfs 时,image/btrfs/layerdb/mounts/<ID>/mount-id 中存有 id,对应于 btrfs/subvolumes 下的目录名。同一目录下的 parent 文件中包含一个 diff_id,通过 image/btrfs/layerdb/sha256/<diff_id>/cache-id 可以查到镜像在 btrfs/subvolumes 下对应的目录名。

容器的配置文件位于config.v2.jsonhostconfig.json中。端口映射位于后者。修改后需要重启 dockerd 才能生效,并且 dockerd 退出时会覆盖修改。

参见

外部链接

参考链接