How to Export a Container in Docker: Simple Guide
Use the
docker export command followed by the container ID or name and redirect the output to a .tar file to export a Docker container. For example, docker export container_name > container.tar saves the container's filesystem as a tar archive.Syntax
The docker export command exports the filesystem of a running or stopped container as a tar archive.
docker export [OPTIONS] CONTAINER: Exports the container's filesystem.CONTAINER: The container ID or name to export.- Redirect the output to a file using
>to save the archive.
bash
docker export [OPTIONS] CONTAINER > filename.tarExample
This example exports a container named mycontainer to a file called mycontainer_export.tar. The tar file contains the container's filesystem without its history or metadata.
bash
docker export mycontainer > mycontainer_export.tarCommon Pitfalls
- Forgetting to redirect output to a file will print the tar archive to the terminal, causing unreadable output.
- Using
docker exportdoes not include Docker image layers or history, only the container filesystem. - To save the image with history, use
docker saveinstead. - Exporting a running container is allowed, but the filesystem may not be consistent if files change during export.
bash
docker export mycontainer # Wrong: outputs tar to terminal docker export mycontainer > mycontainer.tar # Correct: saves tar file
Quick Reference
Remember these tips when exporting containers:
- Use
docker export CONTAINER > file.tarto export. - Exported tar contains only container filesystem.
- Use
docker saveto export images with history. - Redirect output to a file to avoid terminal clutter.
Key Takeaways
Use
docker export CONTAINER > file.tar to export a container's filesystem as a tar archive.Always redirect the output to a file to save the export instead of printing to the terminal.
docker export exports only the container filesystem, not image layers or history.For exporting images with history, use
docker save instead.Exporting a running container may produce inconsistent filesystem snapshots.