MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Docker commands Guide – docker export with examples

Hereโ€™s a complete tutorial on docker export, covering what it does, examples, and use cases.


What is docker export?

docker export is a Docker command used to export the filesystem of a container as a tarball. This allows you to save the container’s data as a single file, which can then be imported or extracted later.

Key Features:

  • Exports the filesystem of a container, excluding image layers and Docker metadata.
  • Useful for creating backups or transferring containers to other systems.
  • Does not preserve container configuration (e.g., environment variables, ports).

Basic Syntax

docker export [OPTIONS] CONTAINER
Code language: JavaScript (javascript)

Options:

  • -o, --output: Write the output to a file instead of standard output.

Examples of docker export

1. Export a Containerโ€™s Filesystem to a Tar File

docker export -o my_container.tar my_container
Code language: JavaScript (javascript)

This saves the filesystem of my_container as a tarball named my_container.tar.


2. Export a Container and Pipe it to Another Command

docker export my_container | gzip > my_container.tar.gz
Code language: JavaScript (javascript)

This compresses the exported filesystem of my_container and saves it as my_container.tar.gz.


3. Extract Files from the Exported Tarball

Export the container:

docker export -o my_container.tar my_container
Code language: JavaScript (javascript)

Extract the tarball contents:

tar -xvf my_container.tar -C /path/to/extract

4. Export and Transfer the Container to Another Machine

Export the container:

docker export -o my_container.tar my_container
Code language: JavaScript (javascript)

Transfer the file to another machine (e.g., using scp):

scp my_container.tar user@remote:/path/to/destination
Code language: JavaScript (javascript)

5. Combine docker export with docker import

Export the container:

docker export -o my_container.tar my_container
Code language: JavaScript (javascript)

Import the tarball as a new image:

docker import my_container.tar my_new_image:latest
Code language: CSS (css)

Run a container from the new image:

docker run -it my_new_image:latest bash
Code language: CSS (css)

6. Export Multiple Containers Using a Script

#!/bin/bash
for container in $(docker ps -q); do
  docker export -o ${container}.tar $container
  echo "Exported $container"
done
Code language: JavaScript (javascript)

This script exports the filesystems of all running containers to separate tar files.


7. Export a Stopped Container

You can export stopped containers as well:

docker export -o stopped_container.tar stopped_container
Code language: JavaScript (javascript)

8. Use docker export with docker cp

Export the filesystem and extract only specific files:

docker export my_container | tar -xvf - ./path/to/file
Code language: JavaScript (javascript)

Use Cases for docker export

1. Backup and Restore

  • Export the entire filesystem of a container for backup purposes.
  • Example: Backup the filesystem of a database container for disaster recovery.

2. Transfer Containers Across Environments

  • Use docker export to transfer container filesystems to other environments or systems.
  • Example: Export a container from a development machine and import it into a production system.

3. Debugging and Inspection

  • Export the container filesystem to analyze or debug its contents.
  • Example: Extract configuration files or logs for debugging purposes.

4. Reduce Image Size for Specific Use Cases

  • Export a container, remove unnecessary files, and re-import it as a lighter image.
  • Example: Create a minimal base image from a container.

5. Sharing Application State

  • Export a container with pre-installed applications or dependencies for easy sharing.

List of Common docker export Commands

CommandDescription
docker export -o my_container.tar my_containerExport a container to a tar file
`docker export my_containergzip > my_container.tar.gz`
`docker export my_containertar -xvf – -C /path`
docker export -o stopped_container.tar stopped_containerExport a stopped container
`docker export my_containerdocker import – my_new_image`
docker export -o /backups/db_backup.tar db_containerBackup a database containerโ€™s filesystem

Best Practices for Using docker export:

  1. Combine with docker import to create portable images from exported containers.
  2. Compress tarballs using tools like gzip or xz to save storage space.
  3. Use meaningful filenames when exporting containers (e.g., include timestamps).
  4. Verify exported tarballs by extracting them and inspecting the contents.
  5. Exclude sensitive data from exported containers before sharing or transferring.

Common Errors and Solutions

  1. “No such container”
    โ†’ Ensure the container exists and is running/stopped. Use docker ps -a to verify.
  2. “Permission denied”
    โ†’ Use elevated privileges (sudo) or ensure the current user has Docker permissions.
  3. “File size too large”
    โ†’ Compress the tarball during export (gzip or xz) or exclude unnecessary files before exporting.
  4. “Exported tarball is incomplete”
    โ†’ Verify the container was running/stopped properly before export.

Combining docker export with Other Commands

Backup and Restore a Container

Export the container:

docker export -o db_backup.tar db_container
Code language: JavaScript (javascript)

Transfer the tarball to another system and re-import it as an image:

docker import db_backup.tar db_image:latest
docker run -it db_image:latest bash
Code language: CSS (css)

Extract Logs from an Exported Container

docker export my_container | tar -xvf - ./var/log
Code language: JavaScript (javascript)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Chef Tutorials: Chef Infra Server & Chef Automate Backup and Restore

Chef Infra Server is backed up with chef-server-ctl backup and restored with chef-server-ctl restore. Chef Automate has its own commands, chef-automate backup create and chef-automate backup restore….

Read More

Debug for Docker Container

To debug a Docker container, check its state and logs first, then its network configuration, then test connectivity from another container on the same network. This page…

Read More

Best Azure DevOps Backup Tools in 2026

Source: Magnific Azure DevOps doesn’t back itself up. Deleted repositories, pipelines, and work items can vanish for good once the recovery window closes, and Microsoft’s own documentation…

Read More

Shell Bash Scripting: Assignment & Excercise – 7

This exercise uses Bash, rsync and SSH to copy a local file to a remote backup server, then sends an email when the copy finishes. Below the…

Read More

MySql Backup and Restore – A Complete Guide

MySQL logical backups are made with mysqldump, which writes a database out as a plain SQL file, and restored with the mysql client, which runs that file…

Read More

Import all MySQL databases at one time in seperate file for Backup

This page shows two ways to back up MySQL: with mysqldump –all-databases you get one large file, and with a shell loop you get one dump file…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x