2016-10-14 18:30:36 -04:00
|
|
|
|
---
|
|
|
|
|
title: "import"
|
|
|
|
|
description: "The import command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
|
keywords: "import, file, system, container"
|
2016-10-14 18:30:36 -04:00
|
|
|
|
---
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-07-28 13:28:23 -04:00
|
|
|
|
<!-- This file is maintained within the docker/cli Github
|
|
|
|
|
repository at https://github.com/docker/cli/. Make all
|
2016-10-19 13:25:45 -04:00
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
|
will be rejected.
|
|
|
|
|
-->
|
|
|
|
|
|
2015-06-21 16:41:38 -04:00
|
|
|
|
# import
|
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
|
```markdown
|
|
|
|
|
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
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
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
|
Options:
|
|
|
|
|
-c, --change value Apply Dockerfile instruction to the created image (default [])
|
|
|
|
|
--help Print usage
|
|
|
|
|
-m, --message string Set commit message for imported image
|
|
|
|
|
```
|
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
|
|
|
|
|
|
|
|
|
The `--change` option will apply `Dockerfile` instructions to the image
|
|
|
|
|
that is created.
|
|
|
|
|
Supported `Dockerfile` instructions:
|
|
|
|
|
`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
|
|
|
|
|
|
|
|
|
This will create a new untagged image.
|
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
|
|
|
|
$ docker import http://example.com/exampleimage.tgz
|
|
|
|
|
```
|
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
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
- Import to docker via pipe and `STDIN`.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
|
|
|
|
$ cat exampleimage.tgz | docker import - exampleimagelocal:new
|
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
- Import with a commit message.
|
2015-08-20 00:01:50 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
|
|
|
|
$ cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new
|
|
|
|
|
```
|
2015-08-20 00:01:50 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
- Import to docker from a local archive.
|
2015-07-25 08:07:24 -04:00
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
2015-07-25 08:07:24 -04:00
|
|
|
|
$ docker import /path/to/exampleimage.tgz
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```
|
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
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
|
|
|
|
$ 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
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
|
```bash
|
|
|
|
|
$ sudo tar -c . | docker import --change "ENV DEBUG true" - exampleimagedir
|
|
|
|
|
```
|
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.
|