Transferring Docker to another disk in Windows
Tags: docker, devops, webdev, tutorial
Published: 2023-11-07 11:42:24

Hello everyone Recently, I ran into the problem of insufficient memory on the main disk for a large project that is being deployed in Docker. The issue of transferring Docker resources to a 1TB HDD is fundamentally important, since there were no other options to deploy the project. And that's what came out of it...

To begin with, I will say that I have a WD Green 120G SSD, where Windows and some important software are installed, and other programs, projects and "personal life" are on the 1TB HDD.

They sent instructions on how to deploy the project, where there was a fairly large MySQL dump of more than 50 GB in size and a lot of containers. Somehow I didn't pay attention to this question, but in the process of a sooooo long installation, Docker collapsed and said:

> I won't work, I turn off altogether, I'm stuffy and there's not enough disk space for me to raise your projects here.
> I'm tired, I'm leaving!

The news was not pleasant. I turned this Docker this way and that according to all the instructions on the Internet and off the documentation, but it was under Windows that nothing came out. And yes, if you're in daemon.if you change the json data-root, then it simply will not work... It's great, isn't it?!

After a lot of time of tests and reconfigurations, I was able to find a solution! You may already know about him, so don't judge him harshly. I'm just trying to help "travelers in the Windows world with castrated hard drives."

And so, stop talking and let's get started. Do everything exactly according to the instructions and you will be happy. I must say right away that I have Windows with Docker on disk C, and I want to move it to disk D, where there is a Programs folder.

```
# shutdown wsl
wsl --shutdown
# export data docker-desktop
wsl --export docker-desktop D:\docker-desktop.tar
# remove data's regestration docker-desktop
wsl --unregister docker-desktop
# import data docker-desktop into new directory
wsl --import docker-desktop D:\wslStore\ D:\docker-desktop.tar --version 2
# remove D:\docker-desktop.tar
```

After these manipulations, all your DockerDesktop stories will be located in D:\wslStore \. But, this does not mean that the data (containers, snapshots, etc.) will also be there. To transfer Docker data, an additional bundle of commands is needed:

```
# shutdown wsl
wsl --shutdown
# export data docker-desktop-data
wsl --export docker-desktop-data D:\docker-desktop-data.tar
# remove data's regestration docker-desktop-data
wsl --unregister docker-desktop-data
# import data docker-desktop-data into new directory
wsl --import docker-desktop-data D:\Programs\Docker\ D:\docker-desktop-data.tar --version 2
# remove D:\docker-desktop-data.tar
```

And only now it is under Windows that your Dokker will store all its junk along the way D:\Programs\Docker\

Similarly, you can transfer Ubuntu and other stories from wsl/Docker to where you need:

```
wsl --export Ubuntu ubuntu.tar
wsl --unregister Ubuntu
wsl --import Ubuntu D:\wslStore\Ubuntu\ ubuntu.tar --version 2
```

I spent a whole day on these solutions: I tried one thing, then another - and here I found a working scheme for changing the Docker data storage directory under Windows.

I hope this information was helpful. Well, if not, then don't hit too hard :)