Docker — a platform for building, deploying and managing applications in containers: lightweight, autonomous and portable environments that run virtually anywhere. Sometimes a container needs to be moved from one server to another — for example, you developed an application on your local computer and want to move it to a server for testing or deployment. In this article I will explain how to package a Docker container and transfer it to another server without data loss — in just six steps.
The container concept itself allows developers and systems administrators to assemble applications into lightweight portable environments: this simplifies development, testing and deployment processes, and also reduces the time spent on configuring environments.
Step 1. Stop the container
Before packing the container, it must be stopped. Use the docker stop command:
$ docker stop <container_name>
Here <container_name> is the name of the container you want to stop.
Step 2. Save the container as an image
To package the container, you need to save it as an image. Use the docker commit command:
$ docker commit <container_name> <image_name>
Here <container_name> is the name of the stopped container, and <image_name> is the name of the image into which the container will be saved.
Step 3. Export the image to a file
To move the image to another server, you need to export it to a file. Use the docker save command:
$ docker save <image_name> > <file_name>.tar
Here <image_name> is the name of the image to be exported, and <file_name> is the name of the file into which the image will be exported.
Step 4. Transfer the file to another server
Copy the file <file_name>.tar to the other server. You can use the scp command:
$ scp <file_name>.tar <user>@<server_ip>:<path>
Here <user> is the username on the remote server, <server_ip> is the IP address of the remote server, and <path> is the path where you want to save the file on the remote server.
Step 5. Import the image on the other server
To use the image on the other server, you need to import it from the file. Use the docker load command:
$ docker load < <file_name>.tar
Step 6. Run the container
After importing the image, you can run the container on the other server. Use the docker run command:
$ docker run -d --name <container_name> <image_name>
Here <container_name> is the name of the container you want to run, and <image_name> is the name of the image you want to use to run the container.
That’s it!
The article was first published on 02.04.2023 on openode.xyz; moved and updated on 04.08.2026.