Copying docker image to another server

Hi all,

Apologies if the terminology I am using isn’t quite correct; I’m still learning about Docker…

I am looking after a series of Docker containers on two old servers that are currently running. They were created by a former employee at my organisation with docker-compose. He has since left and due to lack of documentation and missing dependencies (i.e., some of these containers were first created over 5 years ago), I am unable to re-produce the image using docker-compose.

However, the images are currently running. Is it possible to save these images and bring them back up on another server?

I came across https://stackoverflow.com/questions/23935141/how-to-copy-docker-images-from-one-host-to-another-without-using-a-repository on Stackoverflow and while the question is from 2014, replies since have all seemed to give similar advice. That is, to use the save followed by the load commands.

Assuming this advice is still valid, I have three questions:

  1. I read elsewhere (sorry, I lost the link) that saving and loading isn’t quite the same as a virtual machine. That is, I can issue a docker commit command, but a container isn’t a VM. Changes aren’t guaranteed to be saved. I guess this is something I need to keep in mind, but it is the best that I can do.

  2. I suppose I should stop the containers before trying to do a “save”? To not do this would save it in an inconsistent state?

  3. Lastly, the currently running containers are using Docker versions 18.06.1 and 19.03.11 (two different servers). If I load them on a newer version of Docker (23.0.3), will there be an incompatibility problem? Do I have to load them back on the exact same Docker version?

Oh, both the servers where the containers are currently running on and the server where I intend to load the containers back on are running on Ubuntu. Two fairly old version of Ubuntu (18.04 and 20.04) and the latest LTS (22.04).

Of course I can just try to find out the above, but I wanted to see if something I’m doing is “terribly wrong” that experts might spot easily.

Thank you in advance!

Ray

The link is about exporting image from a local image cache as archive file, and importing the archive file into a local image cache. It is not about containers. Generally you will want to copy the image and persistent state from volumes to the new machine and create a new container.

If you share the compose file and Dockerfile content, we can take a look what needs to be considered.

Note: from a security perspective, it is not advised to run containers based on old, unpatched images.

Regarding the compatibility: In most cases images do work with newer versions of the docker engine.

1 Like

Hi @meyay ,

Thank you for your reply! My apologies for my mistake – clearly I was using “image” and “container” interchangeably. I see where I was wrong now. That an image runs within a container (an instance of an image, perhaps?).

Also, thank you for your kind offer! Several containers (5-10?) are involved – which is a lot of Dockerfile content to go through… But maybe one or two of them can be stopped and restarted without any noticeable impact to users. So, perhaps I will give the save/load a try and be back here with a more precise question if I encounter any problems.

I neglected to mention about my sudden concern – these containers are running on Ubuntu-based VMs that, in turn, run on a Microsoft Windows Server edition that will reach end-of-life soon. And my organisation may block network access to Windows’ versions that have reached EOL… So, even if the containers are currently running happily, I think I will need to do something about them sooner or later.

Thank you so much for your advice!

Ray

If you have many images to migrate, you might find this post helpful: Docker save/load performance - #5 by meyay

Migrating images and volume state from one host to another has another positive effect: afterward you know exactly what needs to be backed up and how it’s done.

1 Like

In addition to @meyay’s powerful command to copy images to a remote server, I have a project on GitHub with some scripts and one of them is copying local volumes to remote servers.

Quote from the README

# format: docker-volume-copy-remote.sh VOLUME_SRC SSH_REMOTE_SRV SSH_REMOTE_PORT [VOLUME_DST]
./bin/docker-volume-copy-remote.sh my-old-volume user@host.tld 22
# or
./bin/docker-volume-copy-remote.sh my-old-volume user@host.tld 22 my-new-volume
2 Likes

Hi @meyay and @rimelek ,

Thank you both for your follow-ups! You’re absolutely right, @meyay – on the one hand, these containers are running fine and I don’t want to disturb them. On the other hand, we are praying every day that the host server doesn’t crash. This is obviously not a good data recovery plan! I think sooner or later, we have to take the containers down and restore them to make sure we can recover from failure.

And thanks for the GitHub link, @rimelek, and the example! I will give it a try!

Thank you both of you for your advice! I feel less worried about moving forward with this! :grinning:

Ray