首页 前端知识 Docker修改daemon.json添加日志后无法启动的问题

Docker修改daemon.json添加日志后无法启动的问题

2024-04-23 22:04:08 前端知识 前端哥 5 29 我要收藏

docker实战(一):centos7 yum安装docker

docker实战(二):基础命令篇

docker实战(三):docker网络模式(超详细)

docker实战(四):docker架构原理

docker实战(五):docker镜像及仓库配置

docker实战(六):docker 网络及数据卷设置

docker实战(七):docker 性质及版本选择

认知升维: 道、法、术、器、势


一:  配置docker日志文件

通过​​/etc/docker/daemon.json​​​配置Docker的​​log-driver​​参数,遇到了Docker无法启动的错误。


配置信息如下:

[root@www ~]# cat /etc/docker/daemon.json 
{
    "registry-mirrors": [
        "https://d8b3zdiw.mirror.aliyuncs.com",
        "https://reg-mirror.qiniu.com/",
        "https://hub-mirror.c.163.com/",
        "https://docker.mirrors.ustc.edu.cn/"
    ],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "5"
    }
     
}

查看日志: journalctl -amu docker 

错误信息:

dockerd-current[3335]: 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: graph: (from flag: /data/docker
8月 18 12:02:09 www.yhchange.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
8月 18 12:02:09 www.yhchange.com systemd[1]: Failed to start Docker Application Container Engine.
8月 18 12:02:09 www.yhchange.com systemd[1]: Unit docker.service entered failed state.
8月 18 12:02:09 www.yhchange.com systemd[1]: docker.service failed.
8月 18 12:05:49 www.yhchange.com systemd[1]: Starting Docker Application Container Engine...
8月 18 12:05:49 www.yhchange.com dockerd-current[3446]: unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: data-root
8月 18 12:05:49 www.yhchange.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
8月 18 12:05:49 www.yhchange.com systemd[1]: Failed to start Docker Application Container Engine.
8月 18 12:05:49 www.yhchange.com systemd[1]: Unit docker.service entered failed state.
8月 18 12:05:49 www.yhchange.com systemd[1]: docker.service failed.


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

二: 可以看到启动的时候会加载EnvironmentFile=-/etc/sysconfig/docker 配置文件

[root@www ~]# cat /usr/lib/systemd/system/docker.service 
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer

[Service]
Type=notify
NotifyAccess=main
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 --graph /data/docker_data \
          --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
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process

[Install]
WantedBy=multi-user.target


看下配置文件信息:

cat  /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

# Do not add registries in this file anymore. Use /etc/containers/registries.conf
# instead. For more information reference the registries.conf(5) man page.

# Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp

# Controls the /etc/cron.daily/docker-logrotate cron job status.
# To disable, uncomment the line below.
# LOGROTATE=false

# docker-latest daemon can be used by starting the docker-latest unitfile.
# To use docker-latest client, uncomment below lines
#DOCKERBINARY=/usr/bin/docker-latest
#DOCKERDBINARY=/usr/bin/dockerd-latest
#DOCKER_CONTAINERD_BINARY=/usr/bin/docker-containerd-latest
#DOCKER_CONTAINERD_SHIM_BINARY=/usr/bin/docker-containerd-shim-latest
 

 三: 去掉配置文件中: --log-driver=journald

 重新启动:
 

[root@www ~]# systemctl daemon-reload
[root@www ~]# systemctl restart docker
[root@www ~]# systemctl status docker
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2023-08-20 11:38:00 CST; 9s ago
     Docs: http://docs.docker.com
 Main PID: 2160 (dockerd-current)
    Tasks: 32
   CGroup: /system.slice/docker.service
           ├─2160 /usr/bin/dockerd-current --graph /data/docker_data --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/doc...
           └─2171 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --r...

8月 20 11:37:59 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:37:59.491453685+08:00" level=info msg="libcontainerd: new containerd process, pid: 2171"
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.615692314+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.617335438+08:00" level=info msg="Loading containers: start."
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.644238265+08:00" level=info msg="Firewalld running: false"
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.829163222+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set ...rred IP address"
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.883382659+08:00" level=info msg="Loading containers: done."
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.937997301+08:00" level=info msg="Daemon has completed initialization"
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.938173411+08:00" level=info msg="Docker daemon" commit="7d71120/1.13.1" graphdriver=overlay2 version=1.13.1
8月 20 11:38:00 www.yhchange.com dockerd-current[2160]: time="2023-08-20T11:38:00.954810143+08:00" level=info msg="API listen on /var/run/docker.sock"
8月 20 11:38:00 www.yhchange.com systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
 


 

转载请注明出处或者链接地址:https://www.qianduange.cn//article/5898.html
标签
docker容器
评论
发布的文章

【Java】JSONArray详解

2024-04-30 12:04:14

Unity——LitJSON的安装

2024-04-30 12:04:06

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!