Skip to content

Instantly share code, notes, and snippets.

@abmmhasan
Last active February 7, 2024 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abmmhasan/6db93ee19de5c5f3394fe35e2c1b320f to your computer and use it in GitHub Desktop.
Save abmmhasan/6db93ee19de5c5f3394fe35e2c1b320f to your computer and use it in GitHub Desktop.
Change Docker container storage location

Windows:

  • Quite docker desktop
  • Open command prompt/powershell
  • List packages (& take note of the name you wanna move, i.e. docker-desktop-data)
wsl --list -v
  • Turn off wsl
wsl  --shutdown
  • Create destination path (preferred to not have any spaces in path)
mkdir path\to\your\new\location
  • Move the data into new location as tar (we moving the package: docker-desktop-data)
wsl --export docker-desktop-data "path\to\your\new\location\docker-desktop-data.tar"
  • Unregister the container data from WSL
wsl --unregister docker-desktop-data
  • Import the data
wsl --import docker-desktop-data "path\to\your\new\location" "path\to\your\new\location\docker-desktop-data.tar" --version 2
  • Delete the tar file
  • Start the docker dektop

In future to install in preferred location

"Docker Desktop Installer.exe" install -accept-license  --installation-dir=<path>\Docker\Docker --wsl-default-data-root=<path>\Docker\Images

Linux:

sudo systemctl stop docker
sudo systemctl stop docker.socket
  • Copy the original application tree (with all folder permissions and contents)
sudo rsync -aqxP /var/lib/docker/ /path/to/your/new/location/docker
  • Edit the docker.service file
sudo vi /lib/systemd/system/docker.service
  • Change the line starting the docker daemon to look for binary inside /path/to/your/new/location/
ExecStart=/usr/bin/dockerd -g /path/to/your/new/location/docker -H fd://
  • Reload the updated service and restart Docker
sudo systemctl daemon-reload
sudo systemctl start docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment