Docker daemon.json配置参数及格式帮助信息

我们知道程序运行,通过修改命令参数或者配置文件配置项,对程序进行修改。Docker也不例外,通过docker.service 增加命令参数或者在/etc/docker/daemon.json中增加配置项均可。

推荐修改daemon.json对docker守护进程进行配置更改(方便维护)。通过dockerd --help,我们可以获知都有哪些参数,但是,daemon.json中该如何配置呢?格式如何?

以下是Linux下允许的配置选项的完整示例:

{
  "allow-nondistributable-artifacts": [],
  "api-cors-header": "",
  "authorization-plugins": [],
  "bip": "",
  "bridge": "",
  "builder": {
    "gc": {
      "enabled": true,
      "defaultKeepStorage": "10GB",
      "policy": [
        { "keepStorage": "10GB", "filter": ["unused-for=2200h"] },
        { "keepStorage": "50GB", "filter": ["unused-for=3300h"] },
        { "keepStorage": "100GB", "all": true }
      ]
    }
  },
  "cgroup-parent": "",
  "containerd": "/run/containerd/containerd.sock",
  "containerd-namespace": "docker",
  "containerd-plugins-namespace": "docker-plugins",
  "data-root": "",
  "debug": true,
  "default-address-pools": [
    {
      "base": "172.30.0.0/16",
      "size": 24
    },
    {
      "base": "172.31.0.0/16",
      "size": 24
    }
  ],
  "default-cgroupns-mode": "private",
  "default-gateway": "",
  "default-gateway-v6": "",
  "default-network-opts": {},
  "default-runtime": "runc",
  "default-shm-size": "64M",
  "default-ulimits": {
    "nofile": {
      "Hard": 64000,
      "Name": "nofile",
      "Soft": 64000
    }
  },
  "dns": [],
  "dns-opts": [],
  "dns-search": [],
  "exec-opts": [],
  "exec-root": "",
  "experimental": false,
  "features": {
    "cdi": true,
    "containerd-snapshotter": true
  },
  "fixed-cidr": "",
  "fixed-cidr-v6": "",
  "group": "",
  "host-gateway-ip": "",
  "hosts": [],
  "proxies": {
    "http-proxy": "http://proxy.example.com:80",
    "https-proxy": "https://proxy.example.com:443",
    "no-proxy": "*.test.example.com,.example.org"
  },
  "icc": false,
  "init": false,
  "init-path": "/usr/libexec/docker-init",
  "insecure-registries": [],
  "ip": "0.0.0.0",
  "ip-forward": false,
  "ip-masq": false,
  "iptables": false,
  "ip6tables": false,
  "ipv6": false,
  "labels": [],
  "live-restore": true,
  "log-driver": "json-file",
  "log-format": "text",
  "log-level": "",
  "log-opts": {
    "cache-disabled": "false",
    "cache-max-file": "5",
    "cache-max-size": "20m",
    "cache-compress": "true",
    "env": "os,customer",
    "labels": "somelabel",
    "max-file": "5",
    "max-size": "10m"
  },
  "max-concurrent-downloads": 3,
  "max-concurrent-uploads": 5,
  "max-download-attempts": 5,
  "mtu": 0,
  "no-new-privileges": false,
  "node-generic-resources": [
    "NVIDIA-GPU=UUID1",
    "NVIDIA-GPU=UUID2"
  ],
  "oom-score-adjust": 0,
  "pidfile": "",
  "raw-logs": false,
  "registry-mirrors": [],
  "runtimes": {
    "cc-runtime": {
      "path": "/usr/bin/cc-runtime"
    },
    "custom": {
      "path": "/usr/local/bin/my-runc-replacement",
      "runtimeArgs": [
        "--debug"
      ]
    }
  },
  "seccomp-profile": "",
  "selinux-enabled": false,
  "shutdown-timeout": 15,
  "storage-driver": "",
  "storage-opts": [],
  "swarm-default-advertise-addr": "",
  "tls": true,
  "tlscacert": "",
  "tlscert": "",
  "tlskey": "",
  "tlsverify": true,
  "userland-proxy": false,
  "userland-proxy-path": "/usr/libexec/docker-proxy",
  "userns-remap": ""
}

当然,随着docker版本迭代,配置参数亦会有变更,最好还是去官网查看帮助文档:

https://docs.docker.com/reference/cli/dockerd/#daemon-configuration-file

### Windows 10 中 Docker Daemon 配置指南 对于希望在 Windows 10 上配置 Docker 守护程序 (daemon) 的用户来说,官方文档提供了详细的指导说明[^2]。通常情况下,在 Windows 平台上安装 Docker Desktop 后,默认会有一个合理的初始配置来满足大多数用户的日常需求。 然而,如果需要进一步自定义守护进程的行为,则可以通过修改 `dockerd` 命令参数实现这一点。具体操作如下: #### 修改 Docker Daemon 参数 为了更改 Docker 守护程序的默认行为,可以编辑或创建位于 `%ProgramData%\Docker\config\daemon.json` 文件中的 JSON 格式配置项。此文件允许指定一系列选项以调整性能、安全性以及其他特性设置。例如,要增加最大并发上传数量,可以在该文件内加入相应字段: ```json { "max-concurrent-uploads": 50 } ``` 需要注意的是,每次对 `daemon.json` 进行改动之后都需要重启 Docker 服务才能使新设定生效。这可通过 PowerShell 或命令提示符执行以下指令完成: ```powershell Restart-Service docker ``` 此外,还可以通过图形界面的方式管理这些高级属性——即打开 Docker Desktop 应用程序并导航至 **Settings** -> **Daemon**, 在这里能够更直观地浏览和应用各种可用选项而无需手动编写代码片段。 #### 使用 Systemd 管理 Docker Service (适用于 Linux) 虽然上述内容主要针对 Windows 用户,但对于那些熟悉 Linux 操作系统的读者而言,也可以考虑采用 systemd 来管理和定制化 Docker 服务启动过程。不过这部分并不直接适用于 Win10 系统环境下的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值