How to transfer docker data to new computer?

Hello All,

I have a Docker for Windows running in my laptop. Now I want to change my laptop but, I am concerned what will happen to existing images and containers. Currently I have multiple images and containers running on my laptop and I need to transfer it to new computer. Is there any way to transfer safely docker data between computers? Does transferring “AppData\Local\Docker\wsl\data\ext4.vhdx” only sufficient for this?

Can anyone please let me know how this could be done without losing data?

Thanks in advance.

1 Like

You should be able to delete your containers and images and recreate everything on the new machine since containers should not contain any persistent data. In that case the only thing that you need to save is your volumes. In case of bind mounts, it is easy, since you just copy files from your old laptop. If you had volumes, stop the containers, and copy the content of your volumes from the virtual machine to your host machine. I have a solution to that (docker-volume-export script) but it requires bash: GitHub - itsziget/scripts-for-docker: Useful scripts you can use with Docker to save some time

Since your containers are stopped, you can also try to find your volumes on the WSL distribution’s filesystem:

While that’s a reasonable answer (and one often offered to a question like @sourabh1107’s), I would point out that sometimes folks may be working with images where “just pulling them down again” may not be so trivial:

  • a) they may be are very large (so did take a long time to pull down, and would again if pulled again), or
  • b) they may no longer exist in the repo from which they were obtained (such as may be the case with containers for products or tools, as opposed to images that one may build–or that colleagues may build–and store in some repo).

This has hit me over the years, and I’ve had this same question in the past (about what file or files might hold all the images, whether something in Windows or something in the WSL container, and whether it was possible/easy/safe to copy/move to a new machine).

The answer may well vary based on Docker Desktop for Windows versions, Windows versions, whether one is using WSL, and more. Sadly, answers offered in the past may also either no longer work or were never good answers–even if they “worked”.

FWIW, someone could consider using docker export, which would save the container to a tar file, which could then be copied to the new machine where docker import could be used to restore it into the new Docker deployment. This may be especially valuable when faced with my situation “b” above.

So @sourabh1107 , if you may be satisfied with @rimelek’s answer (or perhaps that last suggestion of mine), that’s great. But if you may share my perspective that it seems there could be some “better way” (or if you have other reason to want to press on), I just wanted to offer encouragement that it didn’t seem (to me) an unworthy question.

Again, I’ve not researched it again myself for quite a while. Someone may well be able to offer an excellent answer (or better, a resource), that may well cover multiple scenarios. I’m sure many other still have this question.

Thanks for pointing out some potential issues. I admin, my answer was not as detailed as it used to be or sometimes is, so let’s try again.

Just because it is slow, it doesn’t mean it is not the right way :slight_smile: Moving to an other server takes time. Sometimes you need to move everything as quick as it is possible, because of some issues and because your bussiness depends on it, but it you don’t use a stable way to move everything, you can still lose data. Copying the underlying filesystem can work, but you can also make mistakes and damage the filesystem because something happens during copying and you cant guarantee the integrity of your files.

This is exactly why you should use those solutions only with enough knowledge and confidence knowing exactly what you are doing. There are ways working with every Docker instance, like pulling images from a registry (assuming there is no netwok issue)

Good point, however since your images are on the Docker host, you can save the images using

docker image save ...

and load them on the othe rmachine using

docker image load ...

or push them back to a private registry. which is available on both servers at least when you use the commands. So the point of my previous post was that you should never export and import containers. You can still save and load images, but unless you move the data on a usb device, you will use the network to move your images, so installing a local registry, pushing the images into the registry and pulling everything from the other machine may be faster. Even if you use a USB device (and sometimes you have to) then saving images to a tar, copying it to an external disk, moving that to a new server, loading the images on the server. can be slow too. It depends on the speed of the network of course. Since @sourabh1107 asked about two laptops, I guess either of the solutions would work, although firewalls could cause some headache so I would try a private, but not local registry or the external drive approach with saved and loaded images.

When you already made a mistake and installed everything in your container interactively, so you need to save the container, you can still “commit” the container and move it as an image, but it would require some refactoring in the start scripts or compose files.

Docker commit can be useful when you have a very special build process and you have an other tool using some version controlled scripts to install everything in a container and use docker commit at the and. Otherwise I would never use it, but in case you already have an existing container (which I had years ago, when I started to learn Docker), you can use it.

Regarding docker export, keep in mind that it would only export the filesystem of your container, not the metadata and docker import would create a filesystem image, not a container, so you could not easily reuse it. The name of the commands are just misleading, since you would expect to export an entire container and import an entire container.

Sou when you want to move Docker data from one machine to an other, I recommend the following:

  • Stop the docker daemon
  • Try to create a backup of your docker data folder, and do not delete it until you finish moving everything and you could confirm that everything works and not just looks like woking
  • You can try to move the filesystem if you are on a development environment and you don’t mind if something goes wrong but you don’t notice it and 2 days later you realize something is missing because some of your files are corrupted.
  • Save images and volumes in production or when you really don’t want be surprised later.
  • Depending on your exact case, you can move only your volumes or your volumes and images to the new machine
  • Create the volumes on the new machine and copy the data to the volumes from the backup.
  • Optionally load your images or just start the containers and let them download the latest.
  • Start the containers
  • If one of your containers can’t start and you think the reason was a wrong image downloaded from the registry, you can still load your versions, but if you use proper tags with specific versions, your containers will more likely start without errors.

I also have to add that when I work offline, I already have my images saved in tar files or in a private registry so I don’t need to export them or download them from the internet and it still takes time to load everything. The benefit of using registries could be that if you save images into multiple tar files, those images will not share filesystem layers so it could require more space. If you load every image into a single tar file, that may require more memory, but I am not sure in that. I just know load your images, you will not immediately have output indicating that images started to load.

Thank you again @carehart to share your point of view. I was misleading when I stated you need to save volumes only, but saving images or using local registries and saving volumes should be enough. Containers should never be exported and imported though, and never rely only on copying the filesystem. Especially not in case of Docker Desktop which is a special e nvironment compared to Docker CE on Linux and you may need to copy files to an other filesystem (supported by Linux vs supported by Windows).