How to Copy/Move a Docker Container to Another Host

by Karley Harris
17 minutes read

How to Copy/Move a Docker Container to Another Host

A photograph of a individual cleaning on a computer system desk.

Offered that Docker canisters are bit bit boxes of software, you can readily photocopy and also move them around from computer system to computer system. It can be that you functioned on a Docker instance on your municipal computer system and also decided to move it to a additional forceful web server. Or potentially you simply want to deploy your customised canister on plenty of computers, “photocopy and also paste” it around. Other times, you can be irritated with a cloud-untrustworthy solution supplier and also want to switch to a dissimilar one. Below, we reflect you how to move your existent Docker canister image and also information volumes from one Linux host to an additional.

Web content
  • Conserve Canister Photograph from Source Host
  • Exporting a Docker Volume from Your Canister
  • Digits Canister Photograph on Destination Host
  • Importing a Docker Volume to Your Canister
  • Transmit Photograph without Designing a Record
  • Using Docker Write to Glide an Totality Docker Generate

Sweet to diagnose: avail started with canisters by placing Docker on your Linux distro.

Conserve Canister Photograph from Source Host

Overture by listing the accessible Docker canisters dashing on your gizmo. In my pill, I want to export my Nginx Docker canister to a vibrant machine:

docker ps
A incurable emphasizing the accessible Docker canisters for a gizmo.

Situate the canister that you want to photocopy over then guard against the instance:

docker stop NAME_OF_INSTANCE
A incurable verifying the upshot of the docker guard against command.

A Docker canister is cooked up out of a common, initially image. Over time, you add your own readjusts to this substructure image. Processes dashing inside the canister can similarly conserve their own information or earn other readjusts. To retain unanimously of this, perpetrate the present claim of your canister to a vibrant image:

docker commit NAME_OF_INSTANCE mycontainerimage
A incurable verifying the upshot of the docker perpetrate command maturing a vibrant image from the currently dashing one.

Chit that if the instance is currently dashing, this answer will time out it while its contents are saved. If this is a plight, you can stay translucent of this time out by acquiring in docker commit -p=false NAME_OF_INSTANCE mycontainerimage instead. Singularly, don’t execute this unless totally pertinent. The odds of maturing an image with inconsistent/insufficient information surge in this pill.

Presently, conserve your simply recently committed Docker canister image to an archive files:

docker save -o mycontainerimage.tar mycontainerimage

Intake your favored files transfer modality and also photocopy your .tar files to the host where you want to move your Docker canister. For instance, the coordinating with command transmits my Nginx Docker image grossing earn serviceability of of scp:

scp ./mycontainerimage.tar ramces@my.ip.address.here:/home/ramces/

Exporting a Docker Volume from Your Canister

One of the shortcomings of keeping a Docker image is that it doesn’t come with the Docker tools you’ve mount along with your canister. This entails any kind of network bind installs and also the volumes you’ve rendered to storefront your active information.

To satisfactorily export your information slice, initially mount Git on your municipal machine:

sudo apt install git

Run the coordinating with command to download the slice export manuscript for Docker:

git clone https://github.com/ricardobranco777/docker-volumes.sh.git

Administer sure that the export manuscript has the proper authorization snippets, then photocopy it to your machine’s “/usr/municipal/bin:”

sudo chmod +x ./docker-volumes.sh/docker-volumes.sh sudo cp ./docker-volumes.sh/docker-volumes.sh /usr/local/bin/

Test whether your manuscript is cleaning satisfactorily, then remove unanimously the attributed volumes for your canister:

docker-volumes.sh -h docker-volumes.sh NAME_OF_INSTANCE save mycontainerimage-volume.tar
A incurable verifying the procedure of promote upwards any kind of attributed information volumes for a Docker canister.

Send your simply recently archived Docker slice documents to your secluded machine:

scp ./mycontainerimage-volume.tar ramces@my.ip.address.here:/home/ramces/

Digits Canister Photograph on Destination Host

Log in to your secluded host, then rushed the coordinating with command to cluster it to your secluded machine’s Docker daemon:

docker load -i ./mycontainerimage.tar

Intake docker create to reinitialize your Docker canister image with its original rushed flags from your resource machine. For instance, my Nginx Docker canister initially had deportment 80 mapped to my host machine’s deportment 8080:

docker create --name my-nginx-container -p 8080:80 mycontainerimage

Run your simply recently imported Docker canister:

docker start my-nginx-container

Attest that your imported image is cleaning satisfactorily by listing unanimously the vivacious canisters in the gizmo:

docker ps
A incurable verifying unmodified Docker canister image dashing on a dissimilar gizmo.

FYI: rotate your Raspberry Pi proper into a capable portable image gallery by placing Photoprism with Docker.

Importing a Docker Volume to Your Canister

To import a .tar Docker slice files, initially download Git on your vibrant host:

sudo apt install git

Merely prefer with your original gizmo, download the docker-slice.sh underling manuscript, ensconced its approvals snippets to “execute,” then photocopy it to your vibrant machine’s “/usr/municipal/bin” brochure.

A incurable verifying the procedure of receiving and also placing the Docker Volume manuscript for promote upwards information attributed with canisters.

Inflict a vibrant Docker canister grossing earn serviceability of of your exported image files:

docker create --name my-nginx-container -v myvol:/usr/share/nginx/html -p 8080:80 mycontainerimage

Run the docker-slice.sh manuscript with your original .tar files to cluster it to your vibrant gizmo’s Docker daemon:

docker-volumes.sh my-nginx-container load mycontainerimage-volume.tar

Overture your vibrant Docker canister by dashing the coordinating with command:

docker start my-nginx-container

Test if your canister is loading your slice satisfactorily by glancing at its interior config information:

docker inspect -f '{{ .Mounts }}' my-nginx-container
A incurable emphasizing the imported slice information to the vibrant machine.

Transmit Photograph without Designing a Record

Recurrently you can want to miss maturing a mycontainerimage.tar.gz files. Maybe you don’t have enough disk enfranchisement since the canister has innumerable information in it. You can conserve, transfer, and also cluster the image on the destination host in one command. After dashing the docker commit command identified overhead, you can earn serviceability of this:

docker save mycontainerimage | ssh ramces@my.ip.address docker load

It have to job from Windows, too, since it now has a cooked up-in SSH customer (PuTTY not pertinent any kind of longer).

Perpetuate with the docker create command that applies to your circumstance.

A incurable verifying the procedure of maturing a vibrant Docker canister after sending its image via an SSH hose.

Chit: Administer sure that you’ve satisfactorily ranked any kind of Docker slice that was formerly affixed to your canister before launching the imported image.

Finally, prelude your simply recently imported Docker canister by dashing docker start adhered to by your canister’s tag.

A incurable verifying the procedure of launching a vibrant canister and also verifying that it's cleaning satisfactorily.

Using Docker Write to Glide an Totality Docker Generate

With its Write plugin, Docker makes it plausible to build, configure, and also rushed elaborate itineraries without spooking around the web server’s underlying software stack. This, in rotate, permits you to build reproducible masterstroke deployments across dissimilar Linux tools.

To prelude migrating your existent Docker arrangement to Docker Write, initially earn sure that its plugin is currently in your gizmo:

sudo apt install docker-compose-plugin docker-buildx-plugin

Inflict a vibrant folder in your residence brochure for your Docker Write installation:

mkdir ~/my-docker-compose && cd ~/my-docker-compose

Intake your favored text editor to accumulate a “docker-design.yml” files for your masterstroke:

nano ./docker-compose.yml

Paste the coordinating with block of code inside your Write files, then modify it to your matching telephone dubs for:

version: '3'  volumes:   myvol: # Replace with the name of your imported volume.  services:   nginx:     image: mycontainerimage # Replace with the name of your imported Docker image.     ports:       - "8080:80"     volumes:       - myvol:/usr/share/nginx/html # Replace "myvol" with the name of your mounted image.

Conserve your vibrant Write files, then rushed the coordinating with command to prelude it:

docker compose up -d

Finally, test if your Write deployment is cleaning satisfactorily. In my pill, I will test my Nginx Docker canister by opening a net browser and also navigate to “localhost:8080.”

A screenshot verifying the imported Nginx Docker canister cleaning satisfactorily on its vibrant machine host.

Remarking how to photocopy and also move your Docker canister to other Linux hosts is simply one of the few jobs that you can execute with your machine. Locate this magical planet of self-readying by placing a Minecraft web server on Linux grossing earn serviceability of of Docker.

Photograph credit: Max Duzij via Unsplash. All improvements and also screenshots by Ramces Red.

Related Posts