Perplexity

Can I move docker to another partition on MX23 Linux?Stack Overflow

1 step completed

Yes, you can move Docker to another partition on MX Linux by relocating its data directory and updating Docker’s configuration.

Steps to Move Docker Data

  1. Stop Docker Service
    • Stop Docker to avoid data corruption during the transfer:
      text
      sudo systemctl stop docker
      sudo systemctl stop containerd
      
    • This will also stop all running containers.gist.github +1
  2. Copy Docker Data
    • Copy contents from the old Docker data directory (usually /var/lib/docker) to your new partition, e.g. /mnt/new_partition/docker:
      text
      sudo rsync -aP /var/lib/docker/ /mnt/new_partition/docker/
      
    • Alternatively, you can use cp -axT /var/lib/docker /mnt/new_partition/docker.paulsblog +1
  3. Configure Docker to Use the New Directory
    • Edit or create /etc/docker/daemon.json with:
      json
      {
        "data-root": "/mnt/new_partition/docker"
      }
      
    • This directs Docker to use your new data location.github +2
  4. (Optional) Use Symlink or Bind Mount
    • If preferred, you may create a symbolic link instead:
      text
      sudo mv /var/lib/docker /mnt/new_partition/docker
      sudo ln -s /mnt/new_partition/docker /var/lib/docker
      
    • Or use a Linux bind mount if you want only part of Docker data moved (like just volumes):
      text
      sudo mount --bind /mnt/new_partition/docker/volumes /var/lib/docker/volumes
      
    • Update /etc/fstab for persistent mounts.stackoverflow +2
  5. Restart Docker and Verify
    • Restart the Docker service:
      text
      sudo systemctl start docker
      
    • Confirm functionality by running:
      text
      docker info
      
    • Docker should now use the new partition, and all previous images, containers, and volumes will remain available if the copy was done correctly.linuxiac

Key Points

  • Moving Docker’s directory is safe and well-supported; use copy (rsync or cp), update daemon.json, and ensure permissions on the new partition.
  • Symlink or bind mount is an alternative if you prefer not to change the Docker configuration file.
  • Always stop Docker first and validate after the move.

This method works effectively on MX23 Linux and similar Debian-based systems.stackoverflow +4

How to change Docker data-root on MX23 step by step

1 step completed

To change Docker's data-root on MX23 Linux, follow these step-by-step instructions to safely move your Docker data to a new partition and update the configuration for persistent use.reddit +3

Step-by-Step: Change Docker Data-Root on MX23

1. Stop Docker Services

Before making any changes, stop Docker and related services to prevent data corruption:

text
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop containerd

2. Copy Existing Docker Data (Optional, but recommended)

If you want to keep your images, containers, and volumes, copy the content from the old data directory (/var/lib/docker) to your new partition, e.g. /mnt/new_partition/docker:

text
sudo rsync -avxP /var/lib/docker/ /mnt/new_partition/docker/

3. Update Docker Configuration

Edit (or create) /etc/docker/daemon.json to tell Docker where to use the new data-root directory:

text
sudo nano /etc/docker/daemon.json

Insert or update with:

json
{
  "data-root": "/mnt/new_partition/docker"
}

Make sure the path is accurate.diegocarrasco +2

4. (Optional) Update systemd Service (Advanced)

Sometimes an explicit systemd override is required to persist changes after upgrades:

text
sudo nano /lib/systemd/system/docker.service

Find the ExecStart line, and add:

text
--data-root /mnt/new_partition/docker

So it looks like:

text
ExecStart=/usr/bin/dockerd --data-root /mnt/new_partition/docker -H fd:// --containerd=/run/containerd/containerd.sock

5. Reload and Restart Docker

Apply your changes:

text
sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl start docker.socket

6. Verify Changes

To confirm Docker is using the new directory:

text
docker info | grep "Docker Root Dir"

You should see your new path shown.stackoverflow


Notes:

  • Adjust permissions if needed: sudo chown -R root:root /mnt/new_partition/docker
  • After future Docker upgrades, you may need to repeat these steps or check that your settings persist.reddit
  • This process works without data loss when performed carefully, and is suitable for MX23 or other Debian-based distributions.

These steps ensure Docker uses your desired partition for storage, improving disk management and flexibility.ibm +3

Adjust systemd docker.service to persist data-root after upgrades

1 step completed

To make Docker's data-root change persist after upgrades on MX23 Linux, use systemd's override feature instead of directly editing the main docker.service file. This ensures your configuration survives package updates and system reboots.reddit +1

Step-by-Step: Persist Docker data-root with systemd

  1. Create an Override File
    • Run the following command to open the systemd override editor:
      text
      sudo systemctl edit docker.service
      
    • This creates a custom override in /etc/systemd/system/docker.service.d/override.conf instead of modifying /lib/systemd/system/docker.service directly.reddit
  2. Add the data-root Option
    • Add or update the following block in the editor:
      text
      [Service]
      ExecStart=
      ExecStart=/usr/bin/dockerd --data-root /mnt/new_partition/docker -H fd:// --containerd=/run/containerd/containerd.sock
      
    • The first ExecStart= line with no value clears the previous command, while the second sets your new arguments, including the --data-root option.reddit
  3. Reload and Restart Docker
    • Apply your changes:
      text
      sudo systemctl daemon-reload
      sudo systemctl restart docker
      
    • This reloads systemd and restarts Docker using your persisted settings.docker +1
  4. Verify the Data-Root
    • Run:
      text
      docker info | grep "Docker Root Dir"
      
    • Confirm the path matches your new directory.

Notes:

  • Never edit /lib/systemd/system/docker.service directly, as package upgrades will overwrite your changes.docker +1
  • Overrides in /etc/systemd/system/docker.service.d/ persist through upgrades, ensuring your custom data-root isn't lost.

This method provides a robust, upgrade-safe way to keep Docker's data-root on your desired partition on MX23 Linux systems.docker +1

Verify containers and volumes after changing Docker data-root

1 step completed

To verify your containers and volumes after changing Docker's data-root on MX23 Linux, use the following steps to ensure all data is intact and correctly referenced by Docker:

1. Confirm the New Data-Root

Run:

text
docker info --format '{{ .DockerRootDir }}'

Ensure the path matches your new data-root location. This command confirms Docker is pointed at your intended directory.learn-docker.it-sziget

2. List All Containers and Volumes

  • For containers (including stopped):
    text
    docker ps -a
    
  • For volumes:
    text
    docker volume ls
    

Review the output to check that all expected containers and volumes appear.diegocarrasco +1

3. Inspect Volumes

To ensure volume data is accessible, inspect one or more volumes:

text
docker volume inspect <volume_name>

Look for the "Mountpoint" field, which shows you the directory where the volume data is stored. You can verify the contents with:

text
sudo ls -lai $(docker volume inspect <volume_name> --format '{{ .Mountpoint }}')

Check permissions and the presence of expected files within the mountpoint.learn-docker.it-sziget

4. Test Containers and Volume Functionality

  • Start a container that uses a volume and access the filesystem inside:
    text
    docker start <container_name>
    docker exec -it <container_name> /bin/sh
    
  • Access files within the container's mounted volume to confirm data is unaltered.learn-docker.it-sziget

5. Troubleshooting (if Data Seems Missing)

  • Double-check that the old data directory (/var/lib/docker, unless you customized) was fully copied to the new location.
  • If Docker doesn't see your existing containers/volumes, inspect or edit config files in the new data-root (e.g., containers/*/config.v2.json) to ensure paths reference the new directory. If not, update these with the new path using sed or another tool.stackoverflow +1
  • Ensure the new data-root directory has correct ownership and permissions (root:root).

Verifying containers and volumes as described ensures your Docker environment works as intended and all old data remains accessible after a data-root migration.docker +3