@@ -9,11 +9,11 @@ Import the contents from a tarball to create a filesystem image
9
9
10
10
### Options
11
11
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 |
17
17
18
18
19
19
<!-- -MARKER_GEN_END-->
@@ -28,10 +28,6 @@ specify an archive, Docker untars it in the container relative to the `/`
28
28
the host. To import from a remote location, specify a ` URI ` that begins with the
29
29
` http:// ` or ` https:// ` protocol.
30
30
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
-
35
31
## Examples
36
32
37
33
### Import from a remote location
@@ -50,12 +46,6 @@ Import to docker via pipe and `STDIN`.
50
46
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
51
47
```
52
48
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
-
59
49
Import to docker from a local archive.
60
50
61
51
``` console
@@ -68,17 +58,71 @@ $ docker import /path/to/exampleimage.tgz
68
58
$ sudo tar -c . | docker import - exampleimagedir
69
59
```
70
60
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
-
77
61
Note the ` sudo ` in this example – you must preserve
78
62
the ownership of the files (especially root ownership) during the
79
63
archiving with tar. If you are not root (or the sudo command) when you
80
64
tar, then the ownerships might not get preserved.
81
65
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
+
82
126
### When the daemon supports multiple operating systems
83
127
84
128
If the daemon supports multiple operating systems, and the image being imported
@@ -89,3 +133,31 @@ daemon.
89
133
``` console
90
134
$ docker import --platform=linux .\l inuximage.tar
91
135
```
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