github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/docs/reference/commandline/import.md (about)

     1  ---
     2  title: "import"
     3  description: "The import command description and usage"
     4  keywords: "import, file, system, container"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # import
    17  
    18  ```markdown
    19  Usage:  docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
    20  
    21  Import the contents from a tarball to create a filesystem image
    22  
    23  Options:
    24    -c, --change value     Apply Dockerfile instruction to the created image (default [])
    25        --help             Print usage
    26    -m, --message string   Set commit message for imported image
    27  ```
    28  
    29  ## Description
    30  
    31  You can specify a `URL` or `-` (dash) to take data directly from `STDIN`. The
    32  `URL` can point to an archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz)
    33  containing a filesystem or to an individual file on the Docker host.  If you
    34  specify an archive, Docker untars it in the container relative to the `/`
    35  (root). If you specify an individual file, you must specify the full path within
    36  the host. To import from a remote location, specify a `URI` that begins with the
    37  `http://` or `https://` protocol.
    38  
    39  The `--change` option will apply `Dockerfile` instructions to the image
    40  that is created.
    41  Supported `Dockerfile` instructions:
    42  `CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR`
    43  
    44  ## Examples
    45  
    46  ### Import from a remote location
    47  
    48  This will create a new untagged image.
    49  
    50  ```bash
    51  $ docker import http://example.com/exampleimage.tgz
    52  ```
    53  
    54  ### Import from a local file
    55  
    56  - Import to docker via pipe and `STDIN`.
    57  
    58    ```bash
    59    $ cat exampleimage.tgz | docker import - exampleimagelocal:new
    60    ```
    61  
    62  - Import with a commit message.
    63  
    64    ```bash
    65    $ cat exampleimage.tgz | docker import --message "New image imported from tarball" - exampleimagelocal:new
    66    ```
    67  
    68  - Import to docker from a local archive.
    69  
    70    ```bash
    71      $ docker import /path/to/exampleimage.tgz
    72    ```
    73  
    74  ### Import from a local directory
    75  
    76  ```bash
    77  $ sudo tar -c . | docker import - exampleimagedir
    78  ```
    79  
    80  ### Import from a local directory with new configurations
    81  
    82  ```bash
    83  $ sudo tar -c . | docker import --change "ENV DEBUG true" - exampleimagedir
    84  ```
    85  
    86  Note the `sudo` in this example – you must preserve
    87  the ownership of the files (especially root ownership) during the
    88  archiving with tar. If you are not root (or the sudo command) when you
    89  tar, then the ownerships might not get preserved.