Docker export command
overview
docker export tutorial
The docker export command can be used to export the file system inside a Docker container as a tar archive to standard output. The CONTAINER after the docker export command can be the container ID or the container name.
The docker save command is used to save the Docker image as a tar package, pay attention to the difference between the two. The corresponding command of the docker export command is docker import .
docker export syntax
haicoder(www.haicoder.net)# docker export [OPTIONS] CONTAINER
docker export parameters
parameter | illustrate |
---|---|
-o | Write input to a file. |
the case
archive written to file
Use the docker run -it -d command to start a dokcer container.
haicoder(www.haicoder.net)# docker run --name haicoder -it -d centos
919b848515b352c360a8b68fa856c4b69686eef4f4185367e13be33e536ff661
Use the docker export command to output the file system archive information of the docker container to a file.
haicoder(www.haicoder.net)# docker export -o haicoder.tar haicoder
Use the ls command to view the local files, and the archive file haicoder.tar exists, as shown in the following figure:
The archive can be restored into a docker container using the docker import command.
Use **docker kill** and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
Archive non-running containers
Use the docker create -it command to start a dokcer container.
haicoder(www.haicoder.net)# docker create -it --name haicoder centos
2b1589044b9cce9eca970fe01d3c851a2a33ebf4f3e2ae0572009e9112e1c14a
Use the docker export command to output the file system archive information of a docker container that is not running to a file.
haicoder(www.haicoder.net)# docker export -o haicoder.tar haicoder
Use the ls command to view the local files, and the archive file haicoder.tar exists, as shown in the following figure:
Use the docker kill and docker rm commands to remove all containers.
haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`
Summary of docker export command
The docker export command can be used to export the filesystem inside a container to standard output as a tar archive.
The docker export -o command can be used to write the filesystem inside a container to a file as a tar archive.
The docker export command can archive running docker containers or non-running docker containers.
The corresponding command of the docker export command is docker import.