Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The Docker import command

The Docker import command

Docker Command ReferenceDocker Command Reference


docker import This command imports a container snapshot from a tar file or URL to create a new Docker image.

The difference between docker load in Vue 2,docker import A new image can be created from a container snapshot without preserving the image's history and metadata.

Syntax

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

OPTIONS description:

1. Import an image from a local tar file

docker import mycontainer.tar mynewimage:latest

This imports the image from the mycontainer.tar file and names it mynewimage:latest.

2. Import an image from a URL



docker import http://example.com/mycontainer.tar mynewimage:latest

This imports the image from the specified URL and names it mynewimage:latest.

3. Import an image from standard input



cat mycontainer.tar | docker import - mynewimage:latest

This reads the tar file from standard input via a pipe and imports the image.

4. Apply changes during the import process



docker import -c "ENV LANG=en_US.UTF-8" -c "CMD /bin/bash" mycontainer.tar mynewimage:latest

This imports the image from mycontainer.tar and sets the environment variable LANG and the command CMD during the process.

Example

1. Export a container snapshot

First, create and run a container:



docker run -d --name mycontainer ubuntu:20.04 sleep 3600

Export the container snapshot:



docker export mycontainer -o mycontainer.tar

2. Import the container snapshot

Import an image from a tar file:



docker import mycontainer.tar mynewimage:latest

3. Verify the imported image



docker images

Example output:



REPOSITORY     TAG       IMAGE ID            CREATED             SIZE

mynewimage     latest    123abc456def        1 minute ago        72.9MB

4. Run the imported image



docker run -it mynewimage:latest /bin/bash

Notes

docker import This command is a flexible method for creating a new image from a container snapshot, suitable for scenarios such as migrating, restoring, and customizing Docker images. By using the docker import, users can easily generate a new image from a container snapshot and apply extra configuration during the import process.


Docker Command ReferenceDocker Command Reference