0
0
DockerHow-ToBeginner · 3 min read

How to Import a Container in Docker: Simple Steps

To import a container in Docker, use the docker import command followed by the tarball file containing the container filesystem. This command creates a new Docker image from the imported container data.
📐

Syntax

The basic syntax to import a container in Docker is:

  • docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Here:

  • file|URL|- is the path to the tarball file or URL containing the container filesystem.
  • REPOSITORY[:TAG] is an optional name and tag for the new image.
  • OPTIONS can include flags like -c to apply Dockerfile instructions.
bash
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
💻

Example

This example shows how to import a container filesystem saved as a tarball and create a new Docker image named myimportedimage:latest.

bash
docker import mycontainer.tar myimportedimage:latest
Output
sha256:3a1b2c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890
⚠️

Common Pitfalls

Common mistakes when importing containers include:

  • Using docker import to import a container instead of an image tarball. docker import expects a filesystem archive, not a saved image.
  • Confusing docker import with docker load. Use docker load to load images saved with docker save.
  • Not specifying a repository name or tag, which results in an image with a random ID and no easy reference.
bash
Wrong way:
docker import myimage.tar

Right way:
docker import mycontainer.tar myimage:latest
📊

Quick Reference

Remember these tips when importing containers:

  • Use docker import for filesystem tarballs.
  • Use docker load for Docker images saved with docker save.
  • Always tag your imported image for easy use.

Key Takeaways

Use docker import to create an image from a container filesystem tarball.
Specify a repository and tag to name your imported image clearly.
Do not confuse docker import with docker load; they serve different purposes.
Imported images do not include Docker history or metadata, only the filesystem.
Always verify the tarball source and contents before importing.