Skip to content

Instantly share code, notes, and snippets.

@greenygh0st
Created October 31, 2024 14:56
Show Gist options
  • Select an option

  • Save greenygh0st/0db8b42cb091356e81dae0a8a2be918b to your computer and use it in GitHub Desktop.

Select an option

Save greenygh0st/0db8b42cb091356e81dae0a8a2be918b to your computer and use it in GitHub Desktop.
Simple instructions to export a Docker container

To export a Docker container to another host, you can follow these steps:

1. Save the Container as an Image (if needed)

If the container you want to export is running, stop it first:

docker stop <container_id_or_name>

Then, save the container as an image if it's not already an image:

docker commit <container_id_or_name> <image_name>

2. Export the Image to a File

Export the image as a .tar file:

docker save -o <image_name>.tar <image_name>

3. Copy the Image File to the Target Host

You can use scp, rsync, or any other file transfer tool:

scp <image_name>.tar user@remote_host:/path/to/destination

4. Load the Image on the Target Host

SSH into the target host, then load the image:

docker load -i /path/to/destination/<image_name>.tar

5. Run a Container from the Image on the Target Host

Once loaded, you can start a new container from the image:

docker run -d <image_name>

This process effectively transfers your container to another host, maintaining the same configuration and filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment