Docker Import Command
# Docker import Command
[Docker Command Manual](#)
* * *
The `docker import` command is used to import a container snapshot from a tar file or URL to create a new Docker image.
Unlike `docker load`, `docker import` creates a new image from a container snapshot without preserving the image's history and metadata.
### Syntax
docker import file|URL|- [REPOSITORY[:TAG]]
* **`file|URL|-`**: The path to the input file, a local file or URL, or use `-` to read from standard input.
* **`[REPOSITORY[:TAG]]`**: (Optional) Specify the repository and tag for the imported image.
OPTIONS description:
* **`-c, --change`**: Apply Dockerfile instructions during import, such as `CMD`, `ENTRYPOINT`, `ENV`, etc.
* **`-m, --message`**: Add a comment to the imported image.
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 import
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 command CMD during the process.
## Examples
**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 the image from the 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
* Images created with `docker import` do not preserve the original image's history and metadata.
* The `-c` option allows applying Dockerfile instructions during import to customize the new image's configuration.
* The imported tar file must be a container snapshot created with `docker export`, or a compatible format.
The `docker import` command is a flexible method for creating new images from container snapshots, suitable for scenarios involving migration, restoration, and customization of Docker images. By using `docker import`, users can easily generate new images from container snapshots and apply additional configurations during the import process.
* * Docker Command Manual](#)
YouTip