Skip to content

Commit 6f85626

Browse files
authored
Merge pull request #6053 from thaJeztah/import_docs
docs: import: assorted fixes and touch-ups
2 parents a2a1376 + 4520a39 commit 6f85626

File tree

1 file changed

+93
-21
lines changed

1 file changed

+93
-21
lines changed

‎docs/reference/commandline/image_import.md

+93-21
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Import the contents from a tarball to create a filesystem image
99

1010
### Options
1111

12-
| Name | Type | Default | Description |
13-
|:------------------|:---------|:--------|:--------------------------------------------------|
14-
| `-c`, `--change` | `list` | | Apply Dockerfile instruction to the created image |
15-
| `-m`, `--message` | `string` | | Set commit message for imported image |
16-
| `--platform` | `string` | | Set platform if server is multi-platform capable |
12+
| Name | Type | Default | Description |
13+
|:------------------------------------------|:---------|:--------|:--------------------------------------------------|
14+
| [`-c`](#change), [`--change`](#change) | `list` | | Apply Dockerfile instruction to the created image |
15+
| [`-m`](#message), [`--message`](#message) | `string` | | Set commit message for imported image |
16+
| [`--platform`](#platform) | `string` | | Set platform if server is multi-platform capable |
1717

1818

1919
<!---MARKER_GEN_END-->
@@ -28,10 +28,6 @@ specify an archive, Docker untars it in the container relative to the `/`
2828
the host. To import from a remote location, specify a `URI` that begins with the
2929
`http://` or `https://` protocol.
3030

31-
The `--change` option applies `Dockerfile` instructions to the image that is
32-
created. Supported `Dockerfile` instructions:
33-
`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR`
34-
3531
## Examples
3632

3733
### Import from a remote location
@@ -50,12 +46,6 @@ Import to docker via pipe and `STDIN`.
5046
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
5147
```
5248

53-
Import with a commit message.
54-
55-
```console
56-
$ cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new
57-
```
58-
5949
Import to docker from a local archive.
6050

6151
```console
@@ -68,17 +58,71 @@ $ docker import /path/to/exampleimage.tgz
6858
$ sudo tar -c . | docker import - exampleimagedir
6959
```
7060

71-
### Import from a local directory with new configurations
72-
73-
```console
74-
$ sudo tar -c . | docker import --change "ENV DEBUG=true" - exampleimagedir
75-
```
76-
7761
Note the `sudo` in this example – you must preserve
7862
the ownership of the files (especially root ownership) during the
7963
archiving with tar. If you are not root (or the sudo command) when you
8064
tar, then the ownerships might not get preserved.
8165

66+
### <a name="change"></a> Import with new configurations (-c, --change)
67+
68+
The `--change` option applies `Dockerfile` instructions to the image that is
69+
created. Not all `Dockerfile` instructions are supported; the list of instructions
70+
is limited to metadata (configuration) changes. The following `Dockerfile`
71+
instructions are supported:
72+
73+
- [`CMD`](https://docs.docker.com/reference/dockerfile/#cmd)
74+
- [`ENTRYPOINT`](https://docs.docker.com/reference/dockerfile/#entrypoint)
75+
- [`ENV`](https://docs.docker.com/reference/dockerfile/#env)
76+
- [`EXPOSE`](https://docs.docker.com/reference/dockerfile/#expose)
77+
- [`HEALTHCHECK`](https://docs.docker.com/reference/dockerfile/#healthcheck)
78+
- [`LABEL`](https://docs.docker.com/reference/dockerfile/#label)
79+
- [`ONBUILD`](https://docs.docker.com/reference/dockerfile/#onbuild)
80+
- [`STOPSIGNAL`](https://docs.docker.com/reference/dockerfile/#stopsignal)
81+
- [`USER`](https://docs.docker.com/reference/dockerfile/#user)
82+
- [`VOLUME`](https://docs.docker.com/reference/dockerfile/#volume)
83+
- [`WORKDIR`](https://docs.docker.com/reference/dockerfile/#workdir)
84+
85+
The following example imports an image from a TAR-file containing a root-filesystem,
86+
and sets the `DEBUG` environment-variable in the resulting image:
87+
88+
```console
89+
$ docker import --change "ENV DEBUG=true" ./rootfs.tgz exampleimagedir
90+
```
91+
92+
The `--change` option can be set multiple times to apply multiple `Dockerfile`
93+
instructions. The example below sets the `LABEL1` and `LABEL2` labels on
94+
the imported image, in addition to the `DEBUG` environment variable from
95+
the previous example:
96+
97+
```console
98+
$ docker import \
99+
--change "ENV DEBUG=true" \
100+
--change "LABEL LABEL1=hello" \
101+
--change "LABEL LABEL2=world" \
102+
./rootfs.tgz exampleimagedir
103+
```
104+
105+
### <a name="message"></a> Import with a commit message (-m, --message)
106+
107+
The `--message` (or `-m`) option allows you to set a custom comment in
108+
the image's metadata. The following example imports an image from a local
109+
archive and sets a custom message.
110+
111+
```console
112+
$ docker import --message "New image imported from tarball" ./rootfs.tgz exampleimagelocal:new
113+
sha256:25e54c0df7dc49da9093d50541e0ed4508a6b78705057f1a9bebf1d564e2cb00
114+
```
115+
116+
After importing, the message is set in the "Comment" field of the image's
117+
configuration, which is shown when viewing the image's history:
118+
119+
```console
120+
$ docker image history exampleimagelocal:new
121+
122+
IMAGE CREATED CREATED BY SIZE COMMENT
123+
25e54c0df7dc 2 minutes ago 53.6MB New image imported from tarball
124+
```
125+
82126
### When the daemon supports multiple operating systems
83127

84128
If the daemon supports multiple operating systems, and the image being imported
@@ -89,3 +133,31 @@ daemon.
89133
```console
90134
$ docker import --platform=linux .\linuximage.tar
91135
```
136+
137+
### <a name="platform"></a> Set the platform for the imported image (--platform)
138+
139+
The `--platform` option allows you to specify the platform for the imported
140+
image. By default, the daemon's native platform is used as platform, but
141+
the `--platform` option allows you to override the default, for example, in
142+
situations where the imported root filesystem is for a different architecture
143+
or operating system.
144+
145+
The platform option takes the `os[/arch[/variant]]` format; for example,
146+
`linux/amd64` or `linux/arm64/v8`. Architecture and variant are optional,
147+
and default to the daemon's native architecture if omitted.
148+
149+
The following example imports an image from a root-filesystem in `rootfs.tgz`,
150+
and sets the image's platform to `linux/amd64`;
151+
152+
```console
153+
$ docker image import --platform=linux/amd64 ./rootfs.tgz imported:latest
154+
sha256:44a8b44157dad5edcff85f0c93a3e455f3b20a046d025af4ec50ed990d7ebc09
155+
```
156+
157+
After importing the image, the image's platform is set in the image's
158+
configuration;
159+
160+
```console
161+
$ docker image inspect --format '{{.Os}}/{{.Architecture}}' imported:latest
162+
linux/amd64
163+
```

0 commit comments

Comments
 (0)