Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Docker commands Guide – docker import with examples

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


What is docker import?

docker import is a Docker command that creates a new image from a tarball containing a containerโ€™s filesystem. It is often used to restore containers from exported tar files or to create custom images from minimal filesystems.

Key Features:

  • Converts a tarball (container snapshot) into a new Docker image.
  • Restores backup tarballs created with docker export.
  • Allows for custom image creation from external filesystems.
  • Supports adding tags and metadata during the import process.

Basic Syntax

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Code language: JavaScript (javascript)

Options:

  • -c, --change: Apply Dockerfile instructions (e.g., CMD, ENV) to the image during import.
  • -m, --message: Add a commit message to the new image.

Examples of docker import

1. Import a Tarball as a New Image

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

This creates a new image called my_new_image:latest from the tarball my_container.tar.


2. Import a Tarball with a Commit Message

docker import -m "Restored from backup" my_container.tar restored_image:backup
Code language: JavaScript (javascript)

This imports the tarball and adds a message describing the image.


3. Apply Dockerfile Instructions During Import

docker import -c "CMD /bin/bash" my_container.tar custom_image:1.0
Code language: JavaScript (javascript)

This sets the default command (CMD) for the new image to /bin/bash.


4. Import from a Remote URL

docker import https://example.com/container_backup.tar my_remote_image:latest
Code language: JavaScript (javascript)

This imports an image directly from a remote tarball URL.


5. Import and Set Multiple Instructions

docker import -c "ENV APP_ENV=production" -c "CMD /start.sh" my_backup.tar production_image:1.0
Code language: JavaScript (javascript)

This sets an environment variable (APP_ENV) and a startup command (/start.sh).


6. Import a Tarball Using Standard Input

cat my_container.tar | docker import - custom_image:latest
Code language: JavaScript (javascript)

This reads the tarball from standard input and creates a new image.


7. Rebuild a Base Image

docker import minimal_rootfs.tar minimal_image:latest
Code language: CSS (css)

This creates a minimal image from a tarball containing a custom Linux filesystem (minimal_rootfs.tar).


8. Restore an Exported Container

Export the container:

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

Import the tarball as a new image:

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

9. Automate Import with a Script

#!/bin/bash
docker import -c "CMD /bin/bash" /backups/my_container.tar backup_image:$(date +%Y%m%d)
echo "Image imported with tag backup_image:$(date +%Y%m%d)"
Code language: JavaScript (javascript)

Use Cases for docker import

1. Restoring Containers from Backups

  • Use docker import to restore a containerโ€™s filesystem from a backup tarball.
  • Example: Recover a database container from a previously exported snapshot.

2. Creating Minimal Base Images

  • Build custom base images by importing minimal filesystems (e.g., custom Alpine, Ubuntu).
  • Example: Create a stripped-down Linux image from a root filesystem tarball.

3. Custom Image Creation

  • Import tarballs with pre-installed software or configurations and turn them into reusable images.
  • Example: Import a tarball containing an application and its dependencies.

4. Transferring Containers Between Systems

  • Use docker export and docker import to move containers between environments.
  • Example: Transfer a container from a development machine to a production server.

5. Integrating with Legacy Systems

  • Import filesystems from non-Docker environments to create Docker images.
  • Example: Convert a physical serverโ€™s filesystem into a Docker image.

6. Simplifying CI/CD Pipelines

  • Pre-build images with specific dependencies and import them in CI/CD pipelines.

List of Common docker import Commands

CommandDescription
docker import my_container.tar my_image:latestImport a tarball as a new image
docker import -m "Backup on Feb 7" backup.tar my_backup:20260207Import with a commit message
docker import -c "CMD /bin/bash" container.tar custom_image:1.0Set the default command during import
docker import https://example.com/backup.tar remote_image:latestImport a tarball from a URL
`cat my_container.tardocker import – my_image`
docker import minimal_rootfs.tar minimal_imageCreate a minimal image from a custom filesystem
`docker export my_containerdocker import – restored_image`

Best Practices for Using docker import:

  1. Use docker import for restoring containers or creating custom base imagesโ€”not for everyday image builds (prefer Dockerfiles for reproducibility).
  2. Combine with docker export for seamless backup and restore processes.
  3. Add Dockerfile instructions (--change) to set environment variables, commands, or default entrypoints.
  4. Use meaningful tags to track imported images (e.g., backup:20260207).
  5. Verify the imported image by running it and inspecting its configuration (docker inspect).

Common Errors and Solutions

  1. “No such file or directory”
    โ†’ Ensure the tarball exists and the path is correct.
  2. “Permission denied”
    โ†’ Check permissions on the tarball or run the command with sudo.
  3. “Invalid tar file”
    โ†’ Verify that the tarball is properly created and contains the correct filesystem structure.
  4. “Imported image does not start correctly”
    โ†’ Use -c to set the CMD or ENTRYPOINT during import.

Combining docker import with Other Commands

Export and Re-Import for Backup and Restore

Export the container:

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

Re-import it as a new image:

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

Build a Custom Base Image

docker import custom_rootfs.tar my_base_image:1.0
Code language: CSS (css)

Check the Imported Image

docker inspect my_base_image:1.0
docker run -it my_base_image:1.0 bash
Code language: CSS (css)

Find Trusted Cardiac Hospitals

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

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Hereโ€™s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Hereโ€™s an in-depth, step-by-step tutorial and lab manual for Docker Networkingโ€”starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

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