Move docker containers to non-system drive

  • Hi! Dumb question, but I need advice: how to properly move docker containers to another drive?

    For example I want to move my OMV6 to USB flash drive, but move all my containers on nvme drive.

    I have default docker installation via omv-extras

    Will it be enough to copy just this folder to another drive and then change this path /var/lib/docker to new one?

    I need to save all current containers and Portainer also. Docker config are already on another place.

    • Official Post

    Yes that will basically be enough. The procedure is fairly straightforward.


    Stop the docker service

    Code
        systemctl stop docker

    Make sure you have the full UUID for the nvme drive you want to move to

    Copy the folder (that way if something goes wrong, you can start over with /var/lib/docker

    Code
    cp -R /var/lib/docker /srv/some-uuid/docker

    When it's finished go to the omv-extras docker plugin, and place the path in place of /var/lib/docker (ie, in the example above.. /srv/some-uuid/docker)


    CLICK SAVE (this is important)


    Once the new path is saved, Click Install Docker. This will not reinstall docker, it will simply update the docker configs with the new path.


    Once it saves, giive it a moment and refresh and make sure docker shows "Installed and Running".


    Go back to your SSH session and verify docker is looking at the new docker folder


    Code
    docker info | grep Root

    and that should return the new docker path


    Verify all your containers are working as normal (they should be).


    Now you can delete the old docker folder.


    Code
    rm -R /var/lib/docker
  • Thank you so much! Awesome explanation, without your instruction I would definitely forget about one step.

    BTW, instead of using full path I use Symlinks, very great plugin.


    Have done all mentioned steps, all work well, saved 14GB on system drive, now I`m ready to gpart drive to dd backup.

    We can close this thread and mark it as resolved or something.

    • Official Post

    You might want to be careful using a symlink with your docker path... While it *usually* works, there are some containers where this can cause an issue (or so I've read).


    Generally for docker, I use the absolute path. Then for my container volumes/paths, I use symlinks.

    \

  • KM0201

    Added the Label resolved
  • KM0201

    Added the Label OMV 6.x
  • Needed to do this just now, and it mostly worked, though there is no "Click Install Docker" for my version of OMV6 (latest).

    Only a "Reinstall Docker".


    All the dockers are running and their paths point to the new drive which is good.


    But now the mariadb docker is complaining it doesn't have permissions to /var/tmp


    Code
    2024-05-08 [ERROR] mariadbd: Can't create/write to file '/var/tmp/ibXXXXXX' (Errcode: 13 "Permission denied")
    2024-05-08 [ERROR] InnoDB: Unable to create temporary file; errno: 13
    2024-05-08 [ERROR] mariadbd: Can't create/write to file '/var/tmp/ibXXXXXX' (Errcode: 13 "Permission denied")
    2024-05-08 [ERROR] InnoDB: Unable to create temporary file; errno: 13

    I manually chmod 777 /var/tmp from within the docker's bash terminal, and it fixed it for now, but from what other's have said this might break again next boot.


    Any ideas?

  • Okay for anyone else needing to do this, if you follow those instructions you'll likely end up with a bunch of write permissions and lock file errors because cp -R wont preserve permissions.


    So don't do this.

    Code
    cp -R /var/lib/docker /srv/some-uuid/docker

    but his instead.

    Code
    sudo rsync -avzh /var/lib/docker /srv/some-uuid/docker
    • Official Post

    Okay for anyone else needing to do this, if you follow those instructions you'll likely end up with a bunch of write permissions and lock file errors because cp -R wont preserve permissions.


    So don't do this.

    Code
    cp -R /var/lib/docker /srv/some-uuid/docker

    but his instead.

    Code
    sudo rsync -avzh /var/lib/docker /srv/some-uuid/docker

    If you do it as root (or with sudo) you will not have permission issues.

  • Hi I'm new and I know it's an old thread. Just recently I migrated my omv to the new device, minisforum ms-01. I migrated the whole server including docker and containers. For OS it was easy, just inserted disk where omv was installed, edited network via firstaid and for the disk with docker and container data I did next:


    1. Created clonezilla live usb disk and booted into clonezilla

    2. Cloned old docker disk to new Nvme drive

    3. Inserted disk to new pc

    4. Finished


    There was absolutely nothing I had to do after that. Clonezilla even cloned disk with same uuid as before.


    Hope this helps to someone.

  • Before I go ahead and do this, I am running OMV7 with everything up-to-date. I do not see an "Install Docker" option, only "Reinstall Docker". Are there updated steps in OMV7 with the latest Docker Compose plugin to move locations? I am looking to move my Docker install off the system disk and onto a separate NVMe drive. Thanks!


    Apologies for replying to a Resolved post...

    • Official Post

    do not see an "Install Docker" option, only "Reinstall Docker".

    Reinstall = uninstall + install. If there is nothing to uninstall, it will just install. Since you have Docker installed, you want Reinstall anyway.

    Are there updated steps in OMV7 with the latest Docker Compose plugin to move locations?

    If you aren't using named volumes and don't mind downloading images again, I would just change the Docker storage path and click reinstall docker.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Reinstall = uninstall + install. If there is nothing to uninstall, it will just install. Since you have Docker installed, you want Reinstall anyway.

    If you aren't using named volumes and don't mind downloading images again, I would just change the Docker storage path and click reinstall docker.

    Appreciate the advice! I tried this, but ran into issues. I am thinking I might be missing a step, there might be one or more config files that need editing before/after the move, or perhaps there were permissions issues with the new Docker storage location:

    1. Stopped Docker
    2. Copied /var/lib/docker to the new location (/nvme/docker), using rsync command described above
    3. Changed the Docker path to the new (nvme) path in the GUI, hitting Save.
    4. Clicked on Reinstall Docker
    5. "docker info | grep Root" showed my new nvme drive

    Docker indicated it was running, but all my containers were Down and failed/errored whenever I tried to bring them back up manually. As I don't have enough experience with docker to interpret the error messages that popped up, I "panicked" and decided to revert.


    I attempted to restore my old config (/var/lib/docker). It would not come back up at first, but then I remembered I had to edit the /etc/docker/daemon.json file, which was still referencing my nvme location.


    So now I am back to where I started, but everything is at least working well. FYI I have no named volumes. Redownloading images is not a problem either!

    • Official Post

    FYI I have no named volumes. Redownloading images is not a problem either!

    Then why not try the simple instructions I gave?


    Just tested on my dev system. No command line needed.


    Change Docker storage path to /var/lib/docker2 (which does not exist currently)

    Save but don't apply

    Click reinstall docker button

    Start containers.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

    • Official Post

    from the sounds of it you did not copy the folder correctly. Not sure why you used rsync when it is a simple command line to execute the copy.


    If you cd to /nvme


    What is the output of


    ls

  • OK - so I diligently attempted to follow all of the instructions above and in other areas of this Forum, alas to no avail - I was unable to move my docker storage location and have everything work afterwards.


    However... in the end, success! Shockingly, from Google Gemini of all places. For posterity and in case it might help someone else in the future, I thought I would reproduce the steps here. The biggest difference I see here compared to previous advice, is that "systemctl stop docker" did not actually stop any of my containers. I had to individually stop them using the OMV GUI.


    Forum admins - please feel free to delete this post if I inadvertently have provided bad advice. All I can say is that after following it, everything worked well afterwards, and my Docker storage is now independent of my system disk!


    1. Prepare the Data Disk


    Mount the disk: Ensure your data disk is properly mounted in OMV. You can do this through the OMV web interface under Storage > File Systems. Create a mount point for the disk, for example, /srv/dev-disk-by-id-yourdiskid. You could also just use an existing mounted file system.


    Create a Docker directory: Inside the mount point, create a directory to store your Docker data. For example, /srv/dev-disk-by-id-yourdiskid/docker.


    2. Stop Docker and Containers


    Stop the Docker daemon: Use the following command in the OMV command line interface (CLI) to stop the Docker daemon:

    Code
    systemctl stop docker

    Stop all running containers: Make sure all your Docker containers are stopped before proceeding. You can use the following command to list running containers:

    Code
    docker ps

    And then stop them individually using:

    Code
    docker stop <container_name_or_ID>

    3. Copy Docker Data


    Use rsync to copy data: It's essential to preserve file permissions and links when moving Docker data. The rsync command is ideal for this:

    Code
    rsync -aHv /var/lib/docker /srv/dev-disk-by-id-yourdiskid

    This command recursively copies all files and directories from the current Docker storage location (/var/lib/docker) to the new location on your data disk. The -a option ensures that permissions, ownership, and symbolic links are preserved. The -H option preserves hard links, and -v provides verbose output so you can see the progress.


    4. Configure Docker to Use the New Location


    OMV Web Interface: Go to the OMV web interface and navigate to Services > Compose > Settings.


    Change Docker storage path: In the "Docker storage path" field, enter the new path to your Docker data directory on the data disk (e.g., /srv/dev-disk-by-id-yourdiskid/docker).


    Save and Apply: Save the changes in the OMV web interface.


    5. Restart Docker


    Restart the Docker daemon:

    Code
    systemctl start docker

    Verify Docker: Check if Docker is running correctly and using the new storage location:

    Code
    docker info | grep "Docker Root Dir"

    6. Verify Functionality


    Start your containers: Start your Docker containers and ensure they are functioning as expected. This can be done in the OMV GUI


    Check container data: Verify that the data within your containers is accessible and consistent.


    7. Clean Up (only after you are positive everything is working!)


    Remove old Docker directory: Once you've confirmed everything is working correctly, you can safely remove the old Docker directory (/var/lib/docker) to free up space on your system drive.

  • OK - so I diligently attempted to follow all of the instructions above and in other areas of this Forum, alas to no avail - I was unable to move my docker storage location and have everything work afterwards.


    thanks for this. there was one issue though - the rsync command copies files over to /srv/dev-disk-by-id-yourdiskid/docker/docker


    just change the rsync command to

    Code
    rsync -aHv /var/lib/docker /srv/dev-disk-by-id-yourdiskid

    or

    Code
    rsync -aHv /var/lib/* /srv/dev-disk-by-id-yourdiskid/docker

    works great after this

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!