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 import
command allows you to create a Docker image from a tarball of a filesystem. This can be useful when you want to convert a filesystem backup, a virtual machine image, or another system's filesystem into a Docker image. In this tutorial, we will walk through the basics of using the docker import
command.
Prerequisites:
example-container.tar
created in the "Docker export command tutorial".Import the filesystem as a Docker image:
To import a tarball of a filesystem as a Docker image, use the following syntax:
cat FILESYSTEM_TAR | docker import - IMAGE_NAME[:TAG]
Replace FILESYSTEM_TAR
with the path to the tarball of the filesystem, and IMAGE_NAME[:TAG]
with the desired image name and optional tag.
For example, to import the example-container.tar
as a new image named imported-image
, use:
cat example-container.tar | docker import - imported-image
This will create a new image named imported-image
based on the imported filesystem.
List the imported image:
To check if the imported image has been added to your local images, use the docker images
command:
docker images
You should see the imported-image
in the list of images.
Run a container from the imported image:
To run a container from the imported image, use the docker run
command:
docker run -it --name imported-container IMAGE_NAME[:TAG] COMMAND
Replace IMAGE_NAME[:TAG]
with the image name and optional tag, and COMMAND
with the command to run inside the container.
For example, to run a new container named imported-container
from the imported-image
image and start a shell session, use:
docker run -it --name imported-container imported-image /bin/bash
This will start a new container with the filesystem and data from the imported image.
In this tutorial, we covered the basics of using the docker import
command to create a Docker image from a tarball of a filesystem. This can be useful for creating Docker images from system backups, virtual machine images, or other sources. Remember that the docker import
command only imports the filesystem, not the metadata or the configuration settings of the original container or system. You may need to configure the imported image to match your desired settings.
How to Use Docker Import Command:
docker import
command creates a Docker image from a tarball archive containing a container's filesystem.docker import <tarball_path> <image_name>:<tag>
Importing Docker Container Filesystems:
docker export <container_id> > container_export.tar docker import container_export.tar <image_name>:<tag>
Docker Import Command Examples:
docker import
command.docker import container_export.tar <image_name>:<tag> docker import http://example.com/container_export.tar <image_name>:<tag>
Creating Docker Images with Import Command:
docker import --change "CMD ['nginx', '-g', 'daemon off;']" container_export.tar <image_name>:<tag>
Importing Images into Docker with Import:
docker import http://example.com/image_export.tar <image_name>:<tag>
Importing Docker Container Snapshots:
docker export <container_id> > container_export.tar docker import container_export.tar <image_name>:<tag>
Docker Import and Data Migration:
docker export <container_id> > container_export.tar docker import container_export.tar <image_name>:<tag>
Docker Import and Exported Containers:
docker export
to create images from exported container filesystems.docker export <container_id> > container_export.tar docker import container_export.tar <image_name>:<tag>
Importing External Data into Docker Containers:
docker import http://example.com/mydata.tar <image_name>:<tag>