Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
The docker export
command allows you to export a container's filesystem as a tar archive. This is useful when you want to create a backup of the container, share its filesystem, or migrate the container to another system. In this tutorial, we will walk through the basics of using the docker export
command.
Prerequisites:
docker run -it --name example-container ubuntu:20.04 /bin/bash
This command will start a new container based on the ubuntu:20.04
image and open an interactive shell session. The --name
flag is used to assign a name to the container for easier reference.
Export the container filesystem:
To export the container's filesystem as a tar archive, use the following syntax:
docker export CONTAINER > output.tar
Replace CONTAINER
with the container ID or name, and output.tar
with the desired output file name.
For example, to export the example-container
filesystem as a tar archive named example-container.tar
, use:
docker export example-container > example-container.tar
This command will create a tar archive in the current directory containing the container's filesystem.
Inspect the exported filesystem:
You can extract the contents of the tar archive to inspect the exported filesystem using the tar
command:
mkdir extracted-container tar -xf example-container.tar -C extracted-container
This will extract the contents of example-container.tar
into a new directory named extracted-container
. You can now inspect the files and directories that were part of the container's filesystem.
Import the exported filesystem:
If you want to import the exported filesystem as a new container or image, you can use the docker import
command. For example, to import the example-container.tar
as a new image, use:
cat example-container.tar | docker import - example-image
This will create a new image named example-image
based on the exported filesystem. You can then run a new container using this image:
docker run -it --name new-container example-image /bin/bash
In this tutorial, we covered the basics of using the docker export
command to export a container's filesystem as a tar archive. The exported filesystem can be used to create backups, share data, or migrate containers between systems. Remember that the docker export
command only exports the container's filesystem, not the metadata or the configuration settings of the container.
How to Use Docker Export Command:
docker export
command allows you to export a container's filesystem as a tarball, which can be useful for creating backups or sharing container filesystems.docker export <container_id_or_name> > container_export.tar
Creating Tarballs with Docker Export:
docker export <container_id_or_name> | gzip > container_export.tar.gz
Docker Export Command Examples:
docker export
command.docker export -o container_export.tar <container_id_or_name> docker export --output container_export.tar <container_id_or_name>
Exporting Docker Container Filesystem:
docker export <container_id_or_name> > container_export.tar
Importing Exported Containers with Docker:
docker import
to create a new image from an exported tarball, allowing you to reuse or share container filesystems.docker import container_export.tar my_imported_image