首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Docker修改daemon.json后无法启动的问题

Docker修改daemon.json后无法启动的问题

作者头像
大江小浪
发布2018-09-19 17:58:32
6.5K0
发布2018-09-19 17:58:32
举报
文章被收录于专栏:小狼的世界小狼的世界

本文的运行环境为Centos 7.3,Docker与Kubernetes的安装方式见kubeadm安装kubernetes V1.11.1 集群

最近在整理Docker和Kubernetes中的日志与相关配置,在尝试通过/etc/docker/daemon.json配置Docker的log-driver参数,遇到了Docker无法启动的错误。

配置信息如下

{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "1m",
        "max-file": "5"
    }
}

错误提示如下

[root@devops-101 ~]# journalctl -amu  docker
-- Logs begin at Thu 2018-08-30 08:28:53 CST, end at Thu 2018-08-30 08:47:53 CST. --
Aug 30 08:29:07 devops-101 systemd[1]: Starting Docker Application Container Engine...
Aug 30 08:29:08 devops-101 dockerd-current[1102]: 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: log-dri
Aug 30 08:29:08 devops-101 systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Aug 30 08:29:08 devops-101 systemd[1]: Failed to start Docker Application Container Engine.

这个含义应该是Docker启动的时候传入了命令行参数,同时也指定了配置文件,两个配置发生了冲突。那么就查看一下Docker服务启动文件。

[root@devops-101 ~]# vim /usr/lib/systemd/system/docker.service 
[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          --init-path=/usr/libexec/docker/docker-init-current \
          --seccomp-profile=/etc/docker/seccomp.json \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES

可以看到启动的时候会从/etc/sysconfig/docker中获取环境变量。

继续查看这个配置文件。

[root@devops-101 ~]# vim /etc/sysconfig/docker
# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

可以看到参数中默认了--log-driver=journald,把这一段删掉就可以了。重启之后,就可以在/var/log/containers下看到容器产生的日志文件了。

[root@devops-101 containers]# pwd
/var/log/containers
[root@devops-101 containers]# ls 
coredns-78fcdf6894-52gp9_kube-system_coredns-6eea955dfaad8027b9382a9911817057c917e3187dee41502dcd687d8de18729.log
coredns-78fcdf6894-mkvqn_kube-system_coredns-16ed56195ca55c613dec218cfd57c647f8bbe0341b38c446210db98d6ab78f3c.log
etcd-devops-101_kube-system_etcd-42717aa4eda15817f05f35b68f84306ab83fd3f397426c2c9b47d71ebf61942b.log
kube-apiserver-devops-101_kube-system_kube-apiserver-0df17d68a3b1742e9e34620b759b4617f1949bbe2d826b03216419b6994db42c.log
kube-controller-manager-devops-101_kube-system_kube-controller-manager-ee1743e4a4c0114da1cfb32bd78f4f7a576bfc021aacd943e92d2e09cb41116d.log
kube-flannel-ds-7sgps_kube-system_install-cni-92ce6121a1a5456752f502c07ae324676e0d1297261dad266b385a5e6522852c.log
kube-flannel-ds-7sgps_kube-system_kube-flannel-e6eb715062314f175d9fbaa52323f93eeffbb9fa16eed95797c9950884f68b73.log
kube-proxy-79gws_kube-system_kube-proxy-8ce96b3b403d0f7231ca6a004bfec162a093f85ea940867264f50530846d3e0a.log
kube-scheduler-devops-101_kube-system_kube-scheduler-c7ce974eedbc3119320e729310e1b905f65df84dbe46624918dfc33628d9a864.log
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-08-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档