Migrate Docker container to new server
Docker
There are many ways of migrating Docker containers to a different server, today I’ll show you one of the possible approaches.
IMPORTANT: it’s a beginner’s tutorial for copying basic Docker containers (no external dependencies like additional networks or storage volumes).
If you have filesystem volumes attached to your original Docker container, this procedure will not be enough. I’ll publish a more advanced tutorial soon – stay tuned.
This is a simple enough procedure. Steps 1, 2 and 3 should be done on the old server, Steps 4, 5 and 6 should be done on the new server. All you need is root access on both servers and a way to transfer images between the two servers (scp, for instance).
Step 1: Stop Docker container
I’m hoping to transfer the database container called db (container id c745794419a9 below):
Let’s stop the container:
…then make sure it’s down:
Step 2. Commit Docker container to image
Step 3: Save Docker image to a file
Step 4: Transfer Docker image file
Step 5: Load Docker image from a file
On the new server, we docker load the image. Note how it is the same image ID:
Step 6: Start Docker container
Now let’s start a Docker container from this image:
As you can see, it’s running now:
See Also
Docker
There are many ways of migrating Docker containers to a different server, today I’ll show you one of the possible approaches.
IMPORTANT: it’s a beginner’s tutorial for copying basic Docker containers (no external dependencies like additional networks or storage volumes).
If you have filesystem volumes attached to your original Docker container, this procedure will not be enough. I’ll publish a more advanced tutorial soon – stay tuned.
This is a simple enough procedure. Steps 1, 2 and 3 should be done on the old server, Steps 4, 5 and 6 should be done on the new server. All you need is root access on both servers and a way to transfer images between the two servers (scp, for instance).
Step 1: Stop Docker container
I’m hoping to transfer the database container called db (container id c745794419a9 below):
Let’s stop the container:
…then make sure it’s down:
Step 2. Commit Docker container to image
Step 3: Save Docker image to a file
Step 4: Transfer Docker image file
Step 5: Load Docker image from a file
On the new server, we docker load the image. Note how it is the same image ID:
Step 6: Start Docker container
Now let’s start a Docker container from this image:
As you can see, it’s running now: