You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu系统下Docker data-root配置重启后失效的问题求助

Fix: Snap-installed Docker reverts to default data directory after system reboot

I see you're running Docker installed via Snap on Ubuntu 20.04, and you've hit a common quirk with Snap-managed services: when you manually switch the Docker data root to /dockerdata (via daemon.json or modifying docker.service), it sticks after a manual Docker restart—but after a full system reboot, Docker reverts to the Snap default path /var/snap/docker/common/var-lib/docker. Let's break down why this happens and fix it permanently.

Why this happens

Snap packages run in an isolated sandbox, and Snap's built-in service manager handles starting Docker on system boot. It doesn't respect system-level daemon.json or modified docker.service files you set up—instead, it loads its own default configuration unless you explicitly configure Snap-specific Docker settings. Your manual restart works because you're temporarily bypassing Snap's initial startup logic.

Permanent solutions for Snap Docker

This is the simplest, most "Snap-native" way to lock in your custom data directory:

  1. Stop the Docker Snap service first:
    sudo snap stop docker
    
  2. Create the config directory for Snap's Docker instance (if it doesn't exist):
    sudo mkdir -p /var/snap/docker/current/config/
    
  3. Create a daemon.json in this Snap-specific directory to set your custom data root:
    sudo tee /var/snap/docker/current/config/daemon.json <<EOF
    {
      "data-root": "/dockerdata"
    }
    EOF
    
  4. Ensure the /dockerdata directory has the correct permissions (Docker requires root access):
    sudo chown -R root:root /dockerdata
    sudo chmod -R 700 /dockerdata
    
  5. Start the Docker Snap service again:
    sudo snap start docker
    
  6. Verify the change took effect:
    docker info | grep "Docker Root Dir"
    
    You should see /dockerdata listed. Reboot your system and run the verify command again—this time the setting will persist.

Method 2: Switch to systemd management (Optional)

If you prefer using standard systemd to manage Docker instead of Snap's service manager, you can disable the Snap-managed Docker and set up a custom systemd service:

  1. Stop and disable the Snap Docker service:
    sudo snap stop docker
    sudo snap disable docker
    
  2. Create a systemd service file at /etc/systemd/system/docker.service with the following content (note the --data-root /dockerdata flag):
    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network-online.target firewalld.service
    Wants=network-online.target
    
    [Service]
    Type=notify
    ExecStart=/snap/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root /dockerdata
    ExecReload=/bin/kill -s HUP $MAINPID
    TimeoutSec=0
    RestartSec=2
    Restart=always
    StartLimitBurst=3
    StartLimitInterval=60s
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    TasksMax=infinity
    Delegate=yes
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    
  3. Reload systemd and enable the new service:
    sudo systemctl daemon-reload
    sudo systemctl enable --now docker
    
  4. Verify the configuration, then reboot to confirm it persists.

Context from your environment

Looking at your docker version and docker info output:

  • You're running Docker Engine - Community 19.03.12, installed via Snap (evidenced by the original default path)
  • After manual restart, your Docker Root Dir correctly shows /dockerdata—the issue is exclusively Snap overriding this setting on system boot

Method 1 is the best approach since it works within Snap's ecosystem, but Method 2 gives you more control if you're accustomed to systemd service management.

内容的提问来源于stack exchange,提问作者uruloki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 15:38:14