Moving a Docker container from one server to another

To transfer a docker container between servers, you can follow below simple steps. These steps have been tested on CentOS 7, Centos Stream 8 & 9, AlmaLinux 8 & 9, Rocky Linux 8 & 9.

  1. Commit the container to an image: To package a container as an image, you need to first commit the container to an image. You can do this by using the docker commit command. For example, let us assume you are running container with the ID e4d4b3a3a. You can get the container ID by running the docker ps command as below:
    [ ~]# docker ps
    CONTAINER ID  IMAGE            COMMAND       ---
    e4d4b3a3a     myimage:mytag    "/bin/bash"   ---

    You can commit the container to an image using the following command:

    # docker commit e4d4b3a3a myimage:v1 

    This will create a new image with the name myimage and tag v1.

  2. Save the image to a tar archive: To export the image, you need to save it to a tar archive. You can do this using the docker save command. For example, to save the image myimage:v1 to a tar archive called myimage.tar, you would run the following command:
    # docker save myimage:v1 -o myimage.tar 
  3. Transfer the tar archive to the other machine: Once the image is saved to a tar archive, you can transfer it to the other machine using any method that works for you, such as copying it to a USB drive, uploading it to a cloud service, or using a file transfer protocol like SCP.
  4. Load the image on the other machine: On the other machine, you can load the image from the tar archive using the docker load command. For example, to load the image from the myimage.tar archive, you would run the following command:
    # docker load -i myimage.tar 
  5. Verify the image: Once the image is loaded, you can verify that it was loaded successfully by running the docker images command, which should show the image in the list of images on the system.
    # docker images 
  6. Run the container: Once the image is loaded and verified, you can now start your container by running the command below:
    # docker run -it --name mycontainer myimage:v1 /bin/bash 

Leave a reply

Your email address will not be published. Required fields are marked *


©2024 ZMATECH: Innovative solutions for your IT challenges.


We're not around right now. But you can send us an email and we'll get back to you, asap.


Log in with your credentials

Forgot your details?