2015-06-21 13:41:38 -07:00
|
|
|
|
# import
|
|
|
|
|
|
2023-01-06 19:04:05 +01:00
|
|
|
|
<!---MARKER_GEN_START-->
|
2016-07-07 20:43:18 +02:00
|
|
|
|
Import the contents from a tarball to create a filesystem image
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2023-01-06 19:04:05 +01:00
|
|
|
|
### Aliases
|
|
|
|
|
|
|
|
|
|
`docker image import`, `docker import`
|
|
|
|
|
|
|
|
|
|
### Options
|
|
|
|
|
|
2025-05-06 18:41:08 +02:00
|
|
|
|
| Name | Type | Default | Description |
|
|
|
|
|
|:------------------------------------------|:---------|:--------|:--------------------------------------------------|
|
|
|
|
|
| [`-c`](#change), [`--change`](#change) | `list` | | Apply Dockerfile instruction to the created image |
|
|
|
|
|
| [`-m`](#message), [`--message`](#message) | `string` | | Set commit message for imported image |
|
2025-05-06 19:24:46 +02:00
|
|
|
|
| [`--platform`](#platform) | `string` | | Set platform if server is multi-platform capable |
|
2023-01-06 19:04:05 +01:00
|
|
|
|
|
cli: use custom annotation for aliases
Cobra allows for aliases to be defined for a command, but only allows these
to be defined at the same level (for example, `docker image ls` as alias for
`docker image list`). Our CLI has some commands that are available both as a
top-level shorthand as well as `docker <object> <verb>` subcommands. For example,
`docker ps` is a shorthand for `docker container ps` / `docker container ls`.
This patch introduces a custom "aliases" annotation that can be used to print
all available aliases for a command. While this requires these aliases to be
defined manually, in practice the list of aliases rarely changes, so maintenance
should be minimal.
As a convention, we could consider the first command in this list to be the
canonical command, so that we can use this information to add redirects in
our documentation in future.
Before this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
...
With this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
docker image ls, docker image list, docker images
Options:
-a, --all Show all images (default hides intermediate images)
...
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-06-28 10:52:25 +02:00
|
|
|
|
|
2023-01-06 19:04:05 +01:00
|
|
|
|
<!---MARKER_GEN_END-->
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2017-02-07 15:42:48 -08:00
|
|
|
|
## Description
|
|
|
|
|
|
2015-07-25 14:07:24 +02:00
|
|
|
|
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)
|
2015-07-28 01:12:01 -04:00
|
|
|
|
containing a filesystem or to an individual file on the Docker host. If you
|
2015-07-25 14:07:24 +02:00
|
|
|
|
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.
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
2017-02-07 15:42:48 -08:00
|
|
|
|
### Import from a remote location
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2022-03-30 14:33:44 +02:00
|
|
|
|
This creates a new untagged image.
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker import https://example.com/exampleimage.tgz
|
2017-02-07 15:42:48 -08:00
|
|
|
|
```
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2017-02-07 15:42:48 -08:00
|
|
|
|
### Import from a local file
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
Import to docker via pipe and `STDIN`.
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
```console
|
|
|
|
|
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
|
|
|
|
|
```
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
Import to docker from a local archive.
|
2015-07-25 14:07:24 +02:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
```console
|
|
|
|
|
$ docker import /path/to/exampleimage.tgz
|
|
|
|
|
```
|
2015-07-25 14:07:24 +02:00
|
|
|
|
|
2017-02-07 15:42:48 -08:00
|
|
|
|
### Import from a local directory
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
```console
|
2017-02-07 15:42:48 -08:00
|
|
|
|
$ sudo tar -c . | docker import - exampleimagedir
|
|
|
|
|
```
|
2015-06-21 13:41:38 -07:00
|
|
|
|
|
|
|
|
|
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.
|
2018-09-13 10:56:01 -07:00
|
|
|
|
|
2025-05-06 18:41:08 +02:00
|
|
|
|
### <a name="change"></a> 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:
|
|
|
|
|
|
|
|
|
|
- [`CMD`](https://docs.docker.com/reference/dockerfile/#cmd)
|
|
|
|
|
- [`ENTRYPOINT`](https://docs.docker.com/reference/dockerfile/#entrypoint)
|
|
|
|
|
- [`ENV`](https://docs.docker.com/reference/dockerfile/#env)
|
|
|
|
|
- [`EXPOSE`](https://docs.docker.com/reference/dockerfile/#expose)
|
2025-05-06 19:08:35 +02:00
|
|
|
|
- [`HEALTHCHECK`](https://docs.docker.com/reference/dockerfile/#healthcheck)
|
|
|
|
|
- [`LABEL`](https://docs.docker.com/reference/dockerfile/#label)
|
2025-05-06 18:41:08 +02:00
|
|
|
|
- [`ONBUILD`](https://docs.docker.com/reference/dockerfile/#onbuild)
|
2025-05-06 19:08:35 +02:00
|
|
|
|
- [`STOPSIGNAL`](https://docs.docker.com/reference/dockerfile/#stopsignal)
|
2025-05-06 18:41:08 +02:00
|
|
|
|
- [`USER`](https://docs.docker.com/reference/dockerfile/#user)
|
|
|
|
|
- [`VOLUME`](https://docs.docker.com/reference/dockerfile/#volume)
|
|
|
|
|
- [`WORKDIR`](https://docs.docker.com/reference/dockerfile/#workdir)
|
|
|
|
|
|
|
|
|
|
The following example imports an image from a TAR-file containing a root-filesystem,
|
|
|
|
|
and sets the `DEBUG` environment-variable in the resulting image:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ docker import --change "ENV DEBUG=true" ./rootfs.tgz exampleimagedir
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-06 19:38:27 +02:00
|
|
|
|
The `--change` option can be set multiple times to apply multiple `Dockerfile`
|
|
|
|
|
instructions. The example below sets the `LABEL1` and `LABEL2` labels on
|
|
|
|
|
the imported image, in addition to the `DEBUG` environment variable from
|
|
|
|
|
the previous example:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ docker import \
|
|
|
|
|
--change "ENV DEBUG=true" \
|
|
|
|
|
--change "LABEL LABEL1=hello" \
|
|
|
|
|
--change "LABEL LABEL2=world" \
|
|
|
|
|
./rootfs.tgz exampleimagedir
|
|
|
|
|
```
|
|
|
|
|
|
2025-05-06 18:41:08 +02:00
|
|
|
|
### <a name="message"></a> 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.
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ 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:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ docker image history exampleimagelocal:new
|
|
|
|
|
|
|
|
|
|
IMAGE CREATED CREATED BY SIZE COMMENT
|
|
|
|
|
25e54c0df7dc 2 minutes ago 53.6MB New image imported from tarball
|
|
|
|
|
```
|
|
|
|
|
|
2025-04-23 09:57:08 +02:00
|
|
|
|
### When the daemon supports multiple operating systems
|
2020-04-19 15:43:08 +02:00
|
|
|
|
|
2018-09-13 10:56:01 -07:00
|
|
|
|
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.
|
|
|
|
|
|
2021-08-21 14:54:14 +02:00
|
|
|
|
```console
|
2020-04-19 15:43:08 +02:00
|
|
|
|
$ docker import --platform=linux .\linuximage.tar
|
|
|
|
|
```
|
2025-05-06 19:24:46 +02:00
|
|
|
|
|
|
|
|
|
### <a name="platform"></a> Set the platform for the imported image (--platform)
|
|
|
|
|
|
|
|
|
|
The `--platform` option allows you to specify the platform for the imported
|
|
|
|
|
image. By default, the daemon's native platform is used as platform, but
|
|
|
|
|
the `--platform` option allows you to override the default, for example, in
|
|
|
|
|
situations where the imported root filesystem is for a different architecture
|
|
|
|
|
or operating system.
|
|
|
|
|
|
|
|
|
|
The platform option takes the `os[/arch[/variant]]` format; for example,
|
|
|
|
|
`linux/amd64` or `linux/arm64/v8`. Architecture and variant are optional,
|
|
|
|
|
and default to the daemon's native architecture if omitted.
|
|
|
|
|
|
|
|
|
|
The following example imports an image from a root-filesystem in `rootfs.tgz`,
|
|
|
|
|
and sets the image's platform to `linux/amd64`;
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ docker image import --platform=linux/amd64 ./rootfs.tgz imported:latest
|
|
|
|
|
sha256:44a8b44157dad5edcff85f0c93a3e455f3b20a046d025af4ec50ed990d7ebc09
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
After importing the image, the image's platform is set in the image's
|
|
|
|
|
configuration;
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
$ docker image inspect --format '{{.Os}}/{{.Architecture}}' imported:latest
|
|
|
|
|
linux/amd64
|
|
|
|
|
```
|