Migration is unavoidable in many cases. Hardware upgrades, data center changes, outdated operating systems, all of these can be triggers for migration. Docker container migration is often part of a migration task. Today we will see different ways to migrate Docker containers from an existing server to another server. How to migrate Docker container to another server. There is no direct way to migrate Docker container from one server to another. We solve the problem of Docker container migration by using one or more of the following methods. 1. Export and import containersExporting a container means creating a compressed file from the container's file system. The exported file is saved as a "gzip" file. docker export container-name | gzip > container-name.gz Then copy the compressed file to the new server via a file transfer tool such as scp or rsync. In the new server, this gzip file is then imported into a new container. zcat container-name.gz | docker import - container-name The new container created in the new server can be accessed using the "docker run" command. One drawback of the export container tool is that it does not export the container's ports and variables, nor does it export the underlying data that contains the container. This may cause errors when trying to load the container in another server. In this case, we choose Docker image migration to migrate the container from one server to another. 2. Container image migrationThe most common way to migrate a Docker container to another server is to migrate the image that the container is associated with. For the container that must be migrated, first save its Docker image into a compressed file using the "Docker commit" command. docker commit container-id image-name The resulting image will be zipped and uploaded to the new server, where a new container will be created using "docker run". With this method, the data volume is not migrated, but it preserves the data of the application created inside the container. 3. Save and load imagesA Docker image is a package of your application's code, libraries, configuration files, etc. Docker containers are created from these images. You can use "docker save" to compress the image and migrate it to the new server. docker save image-name > image-name.tar In the new server, use "docker load" to use the compressed image file to create a new image. cat image-name.tar | docker load 4. Migrate data volumesData volumes in Docker containers are shared directories that contain container-specific data. The data in the volume is persistent and is not lost during container recreation. When you migrate a Docker container or image from one server to another using the export or commit tools, the underlying data volumes are not migrated. In this case, the directories containing the data will be migrated manually to the new server. Then create a container on the new server, referencing that directory as its data volume. Another simple way is to backup and restore data volumes by passing the “-volumes from” parameter in the “docker run” command. docker run --rm --volumes-from datavolume-name -v $(pwd):/backup image-name tar cvf backup.tar /path-to-datavolume Here, the datavolume name is /path/to/volume. This command provides a backup of the data volume. To specify a working directory, you can also specify -w/backup. The backup generated in the /backup folder can be copied to the new server via scp or ftp tools. The copied backup is then extracted and restored to the data volume in the new container. docker run --rm --volumes-from datavolume-name -v $(pwd):/backup image-name bash -c "cd /path-to-datavolume && tar xvf /backup/backup.tar --strip 1" 5. Migrate the entire Docker containerThe approach we've seen here works for a single container. But in the case where all containers need to be migrated from one server to another, we take another approach. This method involves copying the entire docker directory ("/var/lib/docker") to the new server. In order for this approach to be successful, several key points need to be identified.
If this method does not work due to any failure, we configure custom scripts to migrate containers and images from one server to another. Conclusion: Docker containers are widely used in DevOps and web-based hosting. Today we discussed various ways that Docker engineers can migrate Docker containers to another server in the Docker infrastructure we manage. This concludes the article on 5 ways to migrate Docker containers to other servers. For more information about migrating Docker containers to servers, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Several ways for Vue to achieve communication between components (multiple scenarios)
>>: Free tool to verify that HTML, CSS and RSS feeds are correct
Table of contents 1. Event delegation Event Bubbl...
Introduction to HTML HyperText Markup Language: H...
Effect html <div class="sp-container"...
1. Single row overflow 1. If a single line overfl...
Table of contents 1. Installation 2. There is no ...
Table of contents Vue first screen performance op...
[LeetCode] 184. Department Highest Salary The Emp...
Nginx can use its reverse proxy function to imple...
background Recently, some friends who are new to ...
In MySQL, we usually use limit to complete the pa...
What are :is and :where? :is() and :where() are p...
Preface Any application that can be written in Ja...
Table of contents Preface 1. DDL 1.1 Database Ope...
Table of contents 1. Spark vs. Hadoop 1.1 Disadva...
Table of contents 1. Email 2. Mobile phone number...