【问题标题】:Change docker root path in centos在centos中更改docker根路径
【发布时间】:2018-12-13 01:25:39
【问题描述】:

我正在安装 docker 版本:

Docker version 18.03.1-ce, build 9ee9f40.

OS: centos 7

我想将默认 docker root 更改为 /var/some_path

我发现三种方式

  1. 在文件/etc/sysconfig/docker 中添加(不工作)

    OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false -H tcp://0.0.0.0:2375 -g /var/vms/docker'[centos@ip-172-31-1-225

当我重新加载并重新启动 docker 时,什么也没有发生。根目录为/var/lib/docker

  1. /etc/docker/daemon.json 中添加(不起作用

    { "图": "/var/vms/docker", “存储驱动程序”:“覆盖” }

它抱怨:

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: 

图:(来自标志:/var/lib/docker,来自文件:/var/vms/docker),存储驱动程序:(来自标志:覆盖,来自文件:覆盖)

所以我从/etc/systemd/system/docker.service.d/execstart.conf 中删除了--graph=/opt/afp/docker --storage-driver=overlay

之后当我重新加载并重新启动docker时

sudo systemctl daemon-reload
sudo systemctl restart docker

我收到错误

Error starting daemon: error initializing graphdriver: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior. Reformat the filesystem with ftype=1 to enable d_type support. Backing filesystems without d_type support are not supported.
  1. /etc/systemd/system/docker.service.d/execstart.conf 中添加(不工作):

    ExecStart=/usr/bin/dockerd --graph=/var/lib/vms/docker --storage-driver=overlay

(同时删除步骤 2 中添加的 /etc/docker/daemon.json

我得到同样的错误

Error starting daemon: error initializing graphdriver: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior. Reformat the filesystem with ftype=1 to enable d_type support. Backing filesystems without d_type support are not supported.

注意(重要):当根路径 --graph=/var/lib/docker 时,一切正常。

【问题讨论】:

  • overlay2 也显示相同的错误。同样,当--graph=/var/lib/docker 一切正常时。
  • here 所示,centos 和它的文件系统需要更多的变通方法才能使覆盖(或覆盖2)驱动程序工作。但是,我不知道您为什么需要更改驱动程序才能更改您的docker 路径
  • this 可以帮助您解决问题
  • @Aserre 实际上这是我发现解决问题的 3 种方法中的第一种。 (没解决)
  • 您没有在您展示的代码示例中使用other_args 参数

标签: docker centos docker-compose centos7 docker-swarm


【解决方案1】:
  1. 检查新的挂载路径是 xfs( ftype=1 ) 还是 ext4 分区。 用于检查 xfd:xfs_info 这是因为 docker 文件仅适用于两个分区中的任何一个。 如果上面提到了您的新挂载类型,请执行第 2 步。

  2. 停止泊坞窗 sudo systemctl stop docker

  3. 在 /etc/docker 位置创建一个名为 daemon.json 的文件。

nano /etc/docker/daemon.json

在文件中提供以下信息:

{
    "data-root": "/mnt/customlocation/docker-data",
    "storage-driver": "overlay2"
}
  1. 启动泊坞窗
sudo systemctl stop docker
  1. 验证。输入命令:
docker info

检查 docker 根目录

希望对你有帮助!!!

【讨论】:

    【解决方案2】:

    可以通过创建 systemd 插件服务文件来更改 docker 根目录。当您希望图像和容器或 docker 生成的文件位于另一个分区或驱动器中时,这很有用。

    名称以 .service 结尾的单元配置文件编码有关由 systemd 控制和监督的进程的信息。 Docker 就是其中之一。

    您应该避免直接修改.service 文件,因为它可能在更新期间被覆盖。这就是为什么首选创建 systemd 插入式服务文件的原因。插入式服务文件仅更改感兴趣的特定设置。请注意,如果存在多个插入式文件,则会读取。

    关于这篇文章的更多信息: https://medium.com/@wlarch/change-docker-root-directory-by-creating-a-systemd-drop-in-service-file-3c1244244784

    【讨论】:

      猜你喜欢
      • 2016-11-18
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      相关资源
      最近更新 更多