2015-06-21 16:41:38 -04:00
|
|
|
|
# import
|
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
|
<!---MARKER_GEN_START-->
|
2016-07-07 14:43:18 -04:00
|
|
|
|
Import the contents from a tarball to create a filesystem image
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
|
### 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 |
|
|
|
|
|
|
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 04:52:25 -04:00
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
|
<!---MARKER_GEN_END-->
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
## Description
|
|
|
|
|
|
2015-07-25 08:07:24 -04: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 08:07:24 -04: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 16:41:38 -04:00
|
|
|
|
|
2022-03-30 08:33:44 -04:00
|
|
|
|
The `--change` option applies `Dockerfile` instructions to the image that is
|
|
|
|
|
created. Supported `Dockerfile` instructions:
|
2015-06-21 16:41:38 -04:00
|
|
|
|
`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR`
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
### Import from a remote location
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2022-03-30 08:33:44 -04:00
|
|
|
|
This creates a new untagged image.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
|
|
|
|
$ docker import https://example.com/exampleimage.tgz
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
### Import from a local file
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
Import to docker via pipe and `STDIN`.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
|
|
|
|
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
|
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
Import with a commit message.
|
2015-08-20 00:01:50 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
|
|
|
|
$ cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new
|
|
|
|
|
```
|
2015-08-20 00:01:50 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
Import to docker from a local archive.
|
2015-07-25 08:07:24 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
|
|
|
|
$ docker import /path/to/exampleimage.tgz
|
|
|
|
|
```
|
2015-07-25 08:07:24 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
### Import from a local directory
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
|
$ sudo tar -c . | docker import - exampleimagedir
|
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
### Import from a local directory with new configurations
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
|
```console
|
2020-09-23 06:42:17 -04:00
|
|
|
|
$ sudo tar -c . | docker import --change "ENV DEBUG=true" - exampleimagedir
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```
|
2015-06-21 16:41:38 -04: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 13:56:01 -04:00
|
|
|
|
|
|
|
|
|
## When the daemon supports multiple operating systems
|
2020-04-19 09:43:08 -04:00
|
|
|
|
|
2018-09-13 13:56:01 -04: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 08:54:14 -04:00
|
|
|
|
```console
|
2020-04-19 09:43:08 -04:00
|
|
|
|
$ docker import --platform=linux .\linuximage.tar
|
|
|
|
|
```
|