Export and import Docker containers
This article mainly explains the import and export of Docker containers, which can be used as backups for container snapshots.
Today's picture~
Docker container export
1. First use the command to view the Docker container that has been created
docker ps -a
At this time, you can see that container id
it is the container ID. We only need to export the corresponding container according to the container ID.
2. Export a container
Exporting a container is very simple, using the docker export
command, syntax:docker export $container_id > 容器快照名
3. View the exported container
ls
4. Download the container
View the current path
pwd
Knowing that the container path is under tmp, we can directly use the FTP remote tool to connect to the host for download:
Wait for the container file to download
Import of Docker container
Import a container – docker import command
Once we have a container snapshot, we can import it whenever we want. Import snapshots using the docker import command.
1. First go to the directory where the container file is located
We mentioned above that the directory exported by the container is under tmp, then we go directly to the tmp directory,
cd /tmp
2. Import the container
docker import halo.tar halo:latest
OPTIONS Description:
-halo.tar : select the container filename to import
-halo:latest : specify the container name and version
The process of importing and exporting is similar, and there is no picture demonstration here.
3. You can delete the container file after you are done
rm -rf /tmp/halo.tar