4.4 KiB
import
Import the contents from a tarball to create a filesystem image
Aliases
docker image import
, docker import
Options
Name | Type | Default | Description |
---|---|---|---|
-c , --change |
list |
Apply Dockerfile instruction to the created image | |
-m , --message |
string |
Set commit message for imported image | |
--platform |
string |
Set platform if server is multi-platform capable |
Description
You can specify a URL
or -
(dash) to take data directly from STDIN
. The
URL
can point to an archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz)
containing a filesystem or to an individual file on the Docker host. If you
specify an archive, Docker untars it in the container relative to the /
(root). If you specify an individual file, you must specify the full path within
the host. To import from a remote location, specify a URI
that begins with the
http://
or https://
protocol.
Examples
Import from a remote location
This creates a new untagged image.
$ docker import https://example.com/exampleimage.tgz
Import from a local file
Import to docker via pipe and STDIN
.
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
Import to docker from a local archive.
$ docker import /path/to/exampleimage.tgz
Import from a local directory
$ sudo tar -c . | docker import - exampleimagedir
Note the sudo
in this example – you must preserve
the ownership of the files (especially root ownership) during the
archiving with tar. If you are not root (or the sudo command) when you
tar, then the ownerships might not get preserved.
Import with new configurations (-c, --change)
The --change
option applies Dockerfile
instructions to the image that is
created. Not all Dockerfile
instructions are supported; the list of instructions
is limited to metadata (configuration) changes. The following Dockerfile
instructions are supported:
The following example imports an image from a TAR-file containing a root-filesystem,
and sets the DEBUG
environment-variable in the resulting image:
$ docker import --change "ENV DEBUG=true" ./rootfs.tgz exampleimagedir
Import with a commit message (-m, --message)
The --message
(or -m
) option allows you to set a custom comment in
the image's metadata. The following example imports an image from a local
archive and sets a custom message.
$ docker import --message "New image imported from tarball" ./rootfs.tgz exampleimagelocal:new
sha256:25e54c0df7dc49da9093d50541e0ed4508a6b78705057f1a9bebf1d564e2cb00
After importing, the message is set in the "Comment" field of the image's configuration, which is shown when viewing the image's history:
$ docker image history exampleimagelocal:new
IMAGE CREATED CREATED BY SIZE COMMENT
25e54c0df7dc 2 minutes ago 53.6MB New image imported from tarball
When the daemon supports multiple operating systems
If the daemon supports multiple operating systems, and the image being imported
does not match the default operating system, it may be necessary to add
--platform
. This would be necessary when importing a Linux image into a Windows
daemon.
$ docker import --platform=linux .\linuximage.tar