If you install Docker on Windows - that is, Windows 10 using Hyper-V as basis,
not the Docker Toolbox that uses VirtualBox in the background and is also available
for older Windows versions - the directory where the docker daemon stores all its
images is in C:\ProgramData\Docker
(more specifically the windowsfilter
subdirectory,
but that doesn’t matter here).
However, a C-drive is typically still a smallish SSD drive, i.e. not exactly the right place to store GB of images (albeit the speed is nice). You wouldn’t want that to fill up.
So, I thought that on the electronic internet there should be plenty of information of how to properly move this directory to a different partition. And actually there is, just use your engine of choice and search for terms like “Windows move image directory” or such and you find some information.
Unfortunately, at the time of this writing, all information is scattered around forum posts, superuser.com posts, etc. that only deal with part of the sausage, so I figured I write down what worked for me, just in case.
The first thing, the internet tells you is that you need to add the following to your
c:\ProgramData\Docker\config\daemon.json
configuration file:
You can do that either directly or from the Docker Icon in the notification area of the Windows Task bar. For the following I assume the later, because changing it there will also (conveniently in this case) restart the Docker daemon each time you do. And we’ll do it some time back and forth.
The first thing you want to do is saving your existing images. To do so you can use
the docker save
command. However, there is a pitfall with it. The command would
allow you to save all images into one giant TAR file, or save them by different
selection criteria (e.g. partial image ID).
However the only way that the re-loaded images don’t have missing REPOSITORY and TAG information is to do it like this:
Hence, you need to specify the full repository name. Do that for every image you care to bring over to the new location. And because of the size of most Windows images that may take quite some time.
Also note that I used the -o
option rather than the (usual) output redirection.
At least on my system I had issues and would not get a proper TAR file when using
the docker save microsoft/windowsservercore > wcore.tar
variant. YMMV.
Now go to the docker applet in the task bar, go to “Settings…”, then “Daemon”, switch to “Advanced” and enter the following in the text box (of course you can choose a different path if you like):
Then click “Apply” and the Docker daemon should restart. If you you now do a
docker image list
, you should see no images at all.
Now load the images you saved in the previous step:
This will again take some time, but afterwards you should have the expected
output of docker image list
:
Repeat this step with all images you saved in the previous step.
You could attempt to simple delete the C:\ProgramData\Docker\windowsfilter
folder,
and frankly I did. But I think that there is a “cleaner” solution.
First, go to the docker applet in the task bar, go to “Settings…”, then “Daemon”, and remove what you added in the previous step. That is, the text box should just show:
Then click Apply to restart the Docker daemon. You should now be using your “old” directory as root again. You may want to verify this using the following:
From the command line use docker image rm ...
to remove the images from your
old installation.
Finally, switch back to your new root directory by entering the following again in the daemon settings and restarting the docker daemon.
Please note that the above procedure will leave you with to directories that still matter do Docker: the old one and the new one.
We have simple moved the images. And while the docker daemon will create a complete
looking directory structure in the new graph
directory. Some files are still used
and accessed from the previous location. For example, the daemon’s log file is still
C:\ProgramData\Docker\service.txt
and the daemon.json
file is still expected to
be in C:\ProgramData\Docker\config
.
Cleaning that up is left as a job for another time. My goal was to move the images themselves and for now I can live with the collaterals involved with the above procedure.