Docker 的配置文件说明

简介: 由于 Linux 不同发行版所采用的默认管理框架的不同,Docker 在不同环境下所使用的默认配置文件也有所不同。这给初学者带来了极大的困惑和不便。好消息是,Docker 官方也意识到了这个问题,所以从 V1.12 开始,引入了并行通用配置文件 ```/etc/docker/daemon.json``` 。从此以后,用户可以在所有平台统一通过调整该配置文件来调整 Docker Engine。本文对

由于 Linux 不同发行版所采用的默认管理框架的不同,Docker 在不同环境下所使用的默认配置文件也有所不同。这给初学者带来了极大的困惑和不便。好消息是,Docker 官方也意识到了这个问题,所以从 V1.12 开始,引入了并行通用配置文件 /etc/docker/daemon.json 。从此以后,用户可以在所有平台统一通过调整该配置文件来调整 Docker Engine。本文对此进行简要说明。

配置文件

通用配置文件 /etc/docker/daemon.json

Docker Engine V1.12 之后版本,用户可以自行创建 daemon.json 文件对 Docker Engine 进行配置和调整。要点如下:

  • 该文件作为 Docker Engine 的配置管理文件, 里面几乎涵盖了所有 docker 命令行启动可以配置的参数。
  • 不管是在哪个平台以何种方式启动, Docker 默认都会来这里读取配置。使用户可以统一管理不同系统下的 docker daemon 配置。
  • 相关参数的使用说明,可以参阅 man dockerd 帮助信息,或者参阅官方文档
  • 默认配置文件目录及支持的参数说明:

    • Linux: /etc/docker/daemon.json, 支持的完成参数配置示例如下(最新的支持参数列表可以参阅官方文档):
{
    "authorization-plugins": [],
    "data-root": "",
    "dns": [],
    "dns-opts": [],
    "dns-search": [],
    "exec-opts": [],
    "exec-root": "",
    "experimental": false,
    "storage-driver": "",
    "storage-opts": [],
    "labels": [],
    "live-restore": true,
    "log-driver": "",
    "log-opts": {},
    "mtu": 0,
    "pidfile": "",
    "cluster-store": "",
    "cluster-store-opts": {},
    "cluster-advertise": "",
    "max-concurrent-downloads": 3,
    "max-concurrent-uploads": 5,
    "default-shm-size": "64M",
    "shutdown-timeout": 15,
    "debug": true,
    "hosts": [],
    "log-level": "",
    "tls": true,
    "tlsverify": true,
    "tlscacert": "",
    "tlscert": "",
    "tlskey": "",
    "swarm-default-advertise-addr": "",
    "api-cors-header": "",
    "selinux-enabled": false,
    "userns-remap": "",
    "group": "",
    "cgroup-parent": "",
    "default-ulimits": {},
    "init": false,
    "init-path": "/usr/libexec/docker-init",
    "ipv6": false,
    "iptables": false,
    "ip-forward": false,
    "ip-masq": false,
    "userland-proxy": false,
    "userland-proxy-path": "/usr/libexec/docker-proxy",
    "ip": "0.0.0.0",
    "bridge": "",
    "bip": "",
    "fixed-cidr": "",
    "fixed-cidr-v6": "",
    "default-gateway": "",
    "default-gateway-v6": "",
    "icc": false,
    "raw-logs": false,
    "allow-nondistributable-artifacts": [],
    "registry-mirrors": [],
    "seccomp-profile": "",
    "insecure-registries": [],
    "disable-legacy-registry": false,
    "no-new-privileges": false,
    "default-runtime": "runc",
    "oom-score-adjust": -500,
    "runtimes": {
        "runc": {
            "path": "runc"
        },
        "custom": {
            "path": "/usr/local/bin/my-runc-replacement",
            "runtimeArgs": [
                "--debug"
            ]
        }
    }
}
AI 代码解读
- Windows```%programdata%\docker\config\daemon.json```,支持的完成参数配置示例如下(最新的支持参数列表可以参阅[官方文档](https://docs.docker.com/engine/reference/commandline/dockerd/#on-linux)):
AI 代码解读
{
    "authorization-plugins": [],
    "data-root": "",
    "dns": [],
    "dns-opts": [],
    "dns-search": [],
    "exec-opts": [],
    "experimental": false,
    "storage-driver": "",
    "storage-opts": [],
    "labels": [],
    "log-driver": "",
    "mtu": 0,
    "pidfile": "",
    "cluster-store": "",
    "cluster-advertise": "",
    "max-concurrent-downloads": 3,
    "max-concurrent-uploads": 5,
    "shutdown-timeout": 15,
    "debug": true,
    "hosts": [],
    "log-level": "",
    "tlsverify": true,
    "tlscacert": "",
    "tlscert": "",
    "tlskey": "",
    "swarm-default-advertise-addr": "",
    "group": "",
    "default-ulimits": {},
    "bridge": "",
    "fixed-cidr": "",
    "raw-logs": false,
    "allow-nondistributable-artifacts": [],
    "registry-mirrors": [],
    "insecure-registries": [],
    "disable-legacy-registry": false
}
AI 代码解读

不同框架的配置文件

不同 Linux 发行版本默认使用的管理框架可能存在不同。而不同管理框架下配置文件的架构差异,最终导致了不同环境下默认 Docker 配置文件目录和文件名的不同。Linux 常见管理框架下的默认配置文件说明如下:

| 管理框架类型 | 默认使用该框架的操作系统 | Docker 默认配置文件 | 相关操作指令 |
| - | - | - | - |
| Sysvinit | CentOS 6.x, Ubuntu 12.04 等| /etc/default/docker | CentOS: service docker restart
Ubuntu: /etc/init.d/docker restart |
| Upstart | Ubuntu 14.x,15.x 等| /etc/default/docker| restart docker |
| Systemd | CentOS 7+,Ubunt 16+,Debian,RHEl 7, Fedora, Archlinux 等| Ubuntu/CentOS/: /lib/systemd/system/docker.service
RHEL/CentOS: /usr/lib/systemd/system/docker.service | systemctl restart docker.service |

配置文件修改说明

参阅前述说明,对配置文件调整后,注意如下要点:

  • 修改配置后,需要重启 docker 服务生效。当前主流的 Sytemd 框架相关平台(CentOS 7+,Ubunt 16+ 等)的重启指令如下:
systemctl daemon-reolad
systemctl restart docker.service
AI 代码解读
  • 配置冲突
    如果通用配置文件 /etc/docker/daemon.json 和上述默认配置文件中有配置冲突(相同配置项分别配置了不同值),那么 Docker daemon 启动时会报错。比如,如果在 Ubuntu 16.04 系统中,同时在 /etc/docker/daemon.json 和 /lib/systemd/system/docker.service 中指定了 --dns= 属性,那么 Docker daemon 会启动失败,相关错误信息示例如下:
[root@node3 ~]# systemctl start docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

[root@node3 ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-11-15 15:57:16 CST; 2min 29s ago
     Docs: https://docs.docker.com
  Process: 30610 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0 -H fd:// --dns=223.5.5.5 --dns=223.6.6.6 (code=exited,
 Main PID: 30610 (code=exited, status=1/FAILURE)

Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 systemd[1]: Starting Docker Application Container Engine...
Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 dockerd[30610]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: dns: (from flag: [223.5.5.5  223.6.6.6], from file: [114.114.114.114 8.8.8.8])
Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 systemd[1]: docker.service: Main process exited, code=exite
Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 systemd[1]: Failed to start Docker Application Container En
Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 systemd[1]: docker.service: Unit entered failed state.
Nov 15 15:57:16 c400e32b9e7cd46aea0d484ad260f4e4a-node3 systemd[1]: docker.service: Failed with result 'exit-code'.
lines 1-13/13 (END)
AI 代码解读
目录
打赏
0
0
0
0
78395
分享
相关文章
Prometheus配置docker采集器
本文介绍了如何使用 Prometheus 监控 Docker 容器,涵盖环境准备、配置文件编写及服务启动等步骤。首先确保安装 Docker 和 Docker Compose,接着通过 `docker-compose.yml` 配置 Prometheus 和示例应用。创建 `prometheus.yml` 指定数据采集目标,最后用 `docker-compose up -d` 启动服务。文章还展示了甘特图和类图,帮助理解服务状态与关系,助力提升系统可靠性和可维护性。
110 11
docker pull 相关配置
通过本文的介绍,您已经了解了如何通过镜像源配置、登录私有仓库、设置网络代理以及其他优化策略来提升 `docker pull`命令的效率和可靠性。这些配置不仅能够显著加快镜像下载速度,还能确保在不同网络环境下的稳定性。通过合理使用这些配置,您可以更好地管理和优化Docker环境中的镜像拉取操作。
397 18
Docker Desktop 4.38 安装与配置全流程指南(Windows平台)
Docker Desktop 是容器化应用开发与部署的一体化工具,支持本地创建、管理和运行 Docker 容器。4.38 版本新增 GPU 加速、WSL 2 性能优化和 Kubernetes 1.28 集群管理功能,适用于微服务开发和 CI/CD 流水线搭建。安装要求为 Windows 10 2004 及以上(64 位),需启用 Hyper-V 或 WSL 2。硬件最低配置为 4GB 内存、20GB 存储和虚拟化技术支持的 CPU。安装步骤包括启用系统功能、下载并运行安装程序,完成后配置镜像加速并验证功能。常见问题涵盖 WSL 2 安装不完整、磁盘空间清理及容器外网访问等。
8127 15
在阿里云ECS云服务器上安装、配置及高效使用Docker与Docker Compose
本文介绍了在阿里云ECS上使用Ubuntu系统安装和配置Docker及Docker Compose的详细步骤。通过这些工具,可以快速部署、弹性扩展和高效管理容器化应用,满足开发和运维需求。内容涵盖Docker的安装、镜像源配置、创建Web程序镜像以及使用Docker Compose部署WordPress等实际操作,并分享了使用体验,展示了阿里云实例的高性能和稳定性。
878 4
Docker中配置TLS加密的步骤
我们可以在 Docker 中成功配置 TLS 加密,增强 Docker 环境的安全性,保护容器之间以及与外界的通信安全。需要注意的是,在实际应用中,应根据具体情况进行更细致的配置和调整,确保符合安全要求。同时,定期更新证书和私钥,以保障安全性。
508 60
Docker 镜像加速器配置指南
dockerhub加速器失败,使用第三方加速器
Docker 镜像加速器配置指南
dockerhub加速器失败,使用第三方加速器
Docker容器内进行应用调试与故障排除的方法与技巧,包括使用日志、进入容器检查、利用监控工具及检查配置等,旨在帮助用户有效应对应用部署中的挑战,确保应用稳定运行
本文深入探讨了在Docker容器内进行应用调试与故障排除的方法与技巧,包括使用日志、进入容器检查、利用监控工具及检查配置等,旨在帮助用户有效应对应用部署中的挑战,确保应用稳定运行。
282 5
docker应用部署---Tomcat的部署配置
这篇文章介绍了如何使用Docker部署Tomcat服务器,包括搜索和拉取Tomcat镜像、创建容器并设置端口映射和目录映射,以及如何创建一个HTML页面并使用外部机器访问Tomcat服务器。
docker应用部署---Tomcat的部署配置
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问