github.com/resin-io/docker@v1.13.1/image/spec/v1.1.md (about)

     1  # Docker Image Specification v1.1.0
     2  
     3  An *Image* is an ordered collection of root filesystem changes and the
     4  corresponding execution parameters for use within a container runtime. This
     5  specification outlines the format of these filesystem changes and corresponding
     6  parameters and describes how to create and use them for use with a container
     7  runtime and execution tool.
     8  
     9  This version of the image specification was adopted starting in Docker 1.10.
    10  
    11  ## Terminology
    12  
    13  This specification uses the following terms:
    14  
    15  <dl>
    16      <dt>
    17          Layer
    18      </dt>
    19      <dd>
    20          Images are composed of <i>layers</i>. Each layer is a set of filesystem
    21          changes. Layers do not have configuration metadata such as environment
    22          variables or default arguments - these are properties of the image as a
    23          whole rather than any particular layer.
    24      </dd>
    25      <dt>
    26          Image JSON
    27      </dt>
    28      <dd>
    29          Each image has an associated JSON structure which describes some
    30          basic information about the image such as date created, author, and the
    31          ID of its parent image as well as execution/runtime configuration like
    32          its entry point, default arguments, CPU/memory shares, networking, and
    33          volumes. The JSON structure also references a cryptographic hash of
    34          each layer used by the image, and provides history information for
    35          those layers. This JSON is considered to be immutable, because changing
    36          it would change the computed ImageID. Changing it means creating a new
    37          derived image, instead of changing the existing image.
    38      </dd>
    39      <dt>
    40          Image Filesystem Changeset
    41      </dt>
    42      <dd>
    43          Each layer has an archive of the files which have been added, changed,
    44          or deleted relative to its parent layer. Using a layer-based or union
    45          filesystem such as AUFS, or by computing the diff from filesystem
    46          snapshots, the filesystem changeset can be used to present a series of
    47          image layers as if they were one cohesive filesystem.
    48      </dd>
    49      <dt>
    50          Layer DiffID
    51      </dt>
    52      <dd>
    53          Layers are referenced by cryptographic hashes of their serialized
    54          representation. This is a SHA256 digest over the tar archive used to
    55          transport the layer, represented as a hexadecimal encoding of 256 bits, e.g.,
    56          <code>sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9</code>.
    57          Layers must be packed and unpacked reproducibly to avoid changing the
    58          layer ID, for example by using tar-split to save the tar headers. Note
    59          that the digest used as the layer ID is taken over an uncompressed
    60          version of the tar.
    61      </dd>
    62      <dt>
    63          Layer ChainID
    64      </dt>
    65      <dd>
    66          For convenience, it is sometimes useful to refer to a stack of layers
    67          with a single identifier. This is called a <code>ChainID</code>. For a
    68          single layer (or the layer at the bottom of a stack), the
    69          <code>ChainID</code> is equal to the layer's <code>DiffID</code>.
    70          Otherwise the <code>ChainID</code> is given by the formula:
    71          <code>ChainID(layerN) = SHA256hex(ChainID(layerN-1) + " " + DiffID(layerN))</code>.
    72      </dd>
    73      <dt>
    74          ImageID <a name="id_desc"></a>
    75      </dt>
    76      <dd>
    77          Each image's ID is given by the SHA256 hash of its configuration JSON. It is 
    78          represented as a hexadecimal encoding of 256 bits, e.g.,
    79          <code>sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9</code>.
    80          Since the configuration JSON that gets hashed references hashes of each
    81          layer in the image, this formulation of the ImageID makes images
    82          content-addressable.
    83      </dd>
    84      <dt>
    85          Tag
    86      </dt>
    87      <dd>
    88          A tag serves to map a descriptive, user-given name to any single image
    89          ID. Tag values are limited to the set of characters
    90          <code>[a-zA-Z0-9_.-]</code>, except they may not start with a <code>.</code>
    91          or <code>-</code> character. Tags are limited to 127 characters.
    92      </dd>
    93      <dt>
    94          Repository
    95      </dt>
    96      <dd>
    97          A collection of tags grouped under a common prefix (the name component
    98          before <code>:</code>). For example, in an image tagged with the name
    99          <code>my-app:3.1.4</code>, <code>my-app</code> is the <i>Repository</i>
   100          component of the name. A repository name is made up of slash-separated
   101          name components, optionally prefixed by a DNS hostname. The hostname
   102          must follow comply with standard DNS rules, but may not contain
   103          <code>_</code> characters. If a hostname is present, it may optionally
   104          be followed by a port number in the format <code>:8080</code>.
   105          Name components may contain lowercase characters, digits, and
   106          separators. A separator is defined as a period, one or two underscores,
   107          or one or more dashes. A name component may not start or end with
   108          a separator.
   109      </dd>
   110  </dl>
   111  
   112  ## Image JSON Description
   113  
   114  Here is an example image JSON file:
   115  
   116  ```
   117  {  
   118      "created": "2015-10-31T22:22:56.015925234Z",
   119      "author": "Alyssa P. Hacker &ltalyspdev@example.com&gt",
   120      "architecture": "amd64",
   121      "os": "linux",
   122      "config": {
   123          "User": "alice",
   124          "Memory": 2048,
   125          "MemorySwap": 4096,
   126          "CpuShares": 8,
   127          "ExposedPorts": {  
   128              "8080/tcp": {}
   129          },
   130          "Env": [  
   131              "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
   132              "FOO=docker_is_a_really",
   133              "BAR=great_tool_you_know"
   134          ],
   135          "Entrypoint": [
   136              "/bin/my-app-binary"
   137          ],
   138          "Cmd": [
   139              "--foreground",
   140              "--config",
   141              "/etc/my-app.d/default.cfg"
   142          ],
   143          "Volumes": {
   144              "/var/job-result-data": {},
   145              "/var/log/my-app-logs": {},
   146          },
   147          "WorkingDir": "/home/alice",
   148      },
   149      "rootfs": {
   150        "diff_ids": [
   151          "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
   152          "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
   153        ],
   154        "type": "layers"
   155      },
   156      "history": [
   157        {
   158          "created": "2015-10-31T22:22:54.690851953Z",
   159          "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
   160        },
   161        {
   162          "created": "2015-10-31T22:22:55.613815829Z",
   163          "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]",
   164          "empty_layer": true
   165        }
   166      ]
   167  }
   168  ```
   169  
   170  Note that image JSON files produced by Docker don't contain formatting
   171  whitespace. It has been added to this example for clarity.
   172  
   173  ### Image JSON Field Descriptions
   174  
   175  <dl>
   176      <dt>
   177          created <code>string</code>
   178      </dt>
   179      <dd>
   180          ISO-8601 formatted combined date and time at which the image was
   181          created.
   182      </dd>
   183      <dt>
   184          author <code>string</code>
   185      </dt>
   186      <dd>
   187          Gives the name and/or email address of the person or entity which
   188          created and is responsible for maintaining the image.
   189      </dd>
   190      <dt>
   191          architecture <code>string</code>
   192      </dt>
   193      <dd>
   194          The CPU architecture which the binaries in this image are built to run
   195          on. Possible values include:
   196          <ul>
   197              <li>386</li>
   198              <li>amd64</li>
   199              <li>arm</li>
   200          </ul>
   201          More values may be supported in the future and any of these may or may
   202          not be supported by a given container runtime implementation.
   203      </dd>
   204      <dt>
   205          os <code>string</code>
   206      </dt>
   207      <dd>
   208          The name of the operating system which the image is built to run on.
   209          Possible values include:
   210          <ul>
   211              <li>darwin</li>
   212              <li>freebsd</li>
   213              <li>linux</li>
   214          </ul>
   215          More values may be supported in the future and any of these may or may
   216          not be supported by a given container runtime implementation.
   217      </dd>
   218      <dt>
   219          config <code>struct</code>
   220      </dt>
   221      <dd>
   222          The execution parameters which should be used as a base when running a
   223          container using the image. This field can be <code>null</code>, in
   224          which case any execution parameters should be specified at creation of
   225          the container.
   226  
   227          <h4>Container RunConfig Field Descriptions</h4>
   228  
   229          <dl>
   230              <dt>
   231                  User <code>string</code>
   232              </dt>
   233              <dd>
   234                  <p>The username or UID which the process in the container should
   235                  run as. This acts as a default value to use when the value is
   236                  not specified when creating a container.</p>
   237  
   238                  <p>All of the following are valid:</p>
   239  
   240                  <ul>
   241                      <li><code>user</code></li>
   242                      <li><code>uid</code></li>
   243                      <li><code>user:group</code></li>
   244                      <li><code>uid:gid</code></li>
   245                      <li><code>uid:group</code></li>
   246                      <li><code>user:gid</code></li>
   247                  </ul>
   248  
   249                  <p>If <code>group</code>/<code>gid</code> is not specified, the
   250                  default group and supplementary groups of the given
   251                  <code>user</code>/<code>uid</code> in <code>/etc/passwd</code>
   252                  from the container are applied.</p>
   253              </dd>
   254              <dt>
   255                  Memory <code>integer</code>
   256              </dt>
   257              <dd>
   258                  Memory limit (in bytes). This acts as a default value to use
   259                  when the value is not specified when creating a container.
   260              </dd>
   261              <dt>
   262                  MemorySwap <code>integer</code>
   263              </dt>
   264              <dd>
   265                  Total memory usage (memory + swap); set to <code>-1</code> to
   266                  disable swap. This acts as a default value to use when the
   267                  value is not specified when creating a container.
   268              </dd>
   269              <dt>
   270                  CpuShares <code>integer</code>
   271              </dt>
   272              <dd>
   273                  CPU shares (relative weight vs. other containers). This acts as
   274                  a default value to use when the value is not specified when
   275                  creating a container.
   276              </dd>
   277              <dt>
   278                  ExposedPorts <code>struct</code>
   279              </dt>
   280              <dd>
   281                  A set of ports to expose from a container running this image.
   282                  This JSON structure value is unusual because it is a direct
   283                  JSON serialization of the Go type
   284                  <code>map[string]struct{}</code> and is represented in JSON as
   285                  an object mapping its keys to an empty object. Here is an
   286                  example:
   287  
   288  <pre>{
   289      "8080": {},
   290      "53/udp": {},
   291      "2356/tcp": {}
   292  }</pre>
   293  
   294                  Its keys can be in the format of:
   295                  <ul>
   296                      <li>
   297                          <code>"port/tcp"</code>
   298                      </li>
   299                      <li>
   300                          <code>"port/udp"</code>
   301                      </li>
   302                      <li>
   303                          <code>"port"</code>
   304                      </li>
   305                  </ul>
   306                  with the default protocol being <code>"tcp"</code> if not
   307                  specified.
   308  
   309                  These values act as defaults and are merged with any specified
   310                  when creating a container.
   311              </dd>
   312              <dt>
   313                  Env <code>array of strings</code>
   314              </dt>
   315              <dd>
   316                  Entries are in the format of <code>VARNAME="var value"</code>.
   317                  These values act as defaults and are merged with any specified
   318                  when creating a container.
   319              </dd>
   320              <dt>
   321                  Entrypoint <code>array of strings</code>
   322              </dt>
   323              <dd>
   324                  A list of arguments to use as the command to execute when the
   325                  container starts. This value acts as a  default and is replaced
   326                  by an entrypoint specified when creating a container.
   327              </dd>
   328              <dt>
   329                  Cmd <code>array of strings</code>
   330              </dt>
   331              <dd>
   332                  Default arguments to the entry point of the container. These
   333                  values act as defaults and are replaced with any specified when
   334                  creating a container. If an <code>Entrypoint</code> value is
   335                  not specified, then the first entry of the <code>Cmd</code>
   336                  array should be interpreted as the executable to run.
   337              </dd>
   338              <dt>
   339                  Volumes <code>struct</code>
   340              </dt>
   341              <dd>
   342                  A set of directories which should be created as data volumes in
   343                  a container running this image. This JSON structure value is
   344                  unusual because it is a direct JSON serialization of the Go
   345                  type <code>map[string]struct{}</code> and is represented in
   346                  JSON as an object mapping its keys to an empty object. Here is
   347                  an example:
   348  <pre>{
   349      "/var/my-app-data/": {},
   350      "/etc/some-config.d/": {},
   351  }</pre>
   352              </dd>
   353              <dt>
   354                  WorkingDir <code>string</code>
   355              </dt>
   356              <dd>
   357                  Sets the current working directory of the entry point process
   358                  in the container. This value acts as a default and is replaced
   359                  by a working directory specified when creating a container.
   360              </dd>
   361          </dl>
   362      </dd>
   363      <dt>
   364          rootfs <code>struct</code>
   365      </dt>
   366      <dd>
   367          The rootfs key references the layer content addresses used by the
   368          image. This makes the image config hash depend on the filesystem hash.
   369          rootfs has two subkeys:
   370  
   371          <ul>
   372            <li>
   373              <code>type</code> is usually set to <code>layers</code>.
   374            </li>
   375            <li>
   376              <code>diff_ids</code> is an array of layer content hashes (<code>DiffIDs</code>), in order from bottom-most to top-most.
   377            </li>
   378          </ul>
   379  
   380  
   381          Here is an example rootfs section:
   382  
   383  <pre>"rootfs": {
   384    "diff_ids": [
   385      "sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
   386      "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
   387      "sha256:13f53e08df5a220ab6d13c58b2bf83a59cbdc2e04d0a3f041ddf4b0ba4112d49"
   388    ],
   389    "type": "layers"
   390  }</pre>
   391      </dd>
   392      <dt>
   393          history <code>struct</code>
   394      </dt>
   395      <dd>
   396          <code>history</code> is an array of objects describing the history of
   397          each layer. The array is ordered from bottom-most layer to top-most
   398          layer. The object has the following fields.
   399  
   400          <ul>
   401            <li>
   402              <code>created</code>: Creation time, expressed as a ISO-8601 formatted
   403              combined date and time
   404            </li>
   405            <li>
   406              <code>author</code>: The author of the build point
   407            </li>
   408            <li>
   409              <code>created_by</code>: The command which created the layer
   410            </li>
   411            <li>
   412              <code>comment</code>: A custom message set when creating the layer
   413            </li>
   414            <li>
   415              <code>empty_layer</code>: This field is used to mark if the history
   416              item created a filesystem diff. It is set to true if this history
   417              item doesn't correspond to an actual layer in the rootfs section
   418              (for example, a command like ENV which results in no change to the
   419              filesystem).
   420            </li>
   421          </ul>
   422  
   423  Here is an example history section:
   424  
   425  <pre>"history": [
   426    {
   427      "created": "2015-10-31T22:22:54.690851953Z",
   428      "created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
   429    },
   430    {
   431      "created": "2015-10-31T22:22:55.613815829Z",
   432      "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]",
   433      "empty_layer": true
   434    }
   435  ]</pre>
   436      </dd>
   437  </dl>
   438  
   439  Any extra fields in the Image JSON struct are considered implementation
   440  specific and should be ignored by any implementations which are unable to
   441  interpret them.
   442  
   443  ## Creating an Image Filesystem Changeset
   444  
   445  An example of creating an Image Filesystem Changeset follows.
   446  
   447  An image root filesystem is first created as an empty directory. Here is the
   448  initial empty directory structure for the a changeset using the
   449  randomly-generated directory name `c3167915dc9d` ([actual layer DiffIDs are
   450  generated based on the content](#id_desc)).
   451  
   452  ```
   453  c3167915dc9d/
   454  ```
   455  
   456  Files and directories are then created:
   457  
   458  ```
   459  c3167915dc9d/
   460      etc/
   461          my-app-config
   462      bin/
   463          my-app-binary
   464          my-app-tools
   465  ```
   466  
   467  The `c3167915dc9d` directory is then committed as a plain Tar archive with
   468  entries for the following files:
   469  
   470  ```
   471  etc/my-app-config
   472  bin/my-app-binary
   473  bin/my-app-tools
   474  ```
   475  
   476  To make changes to the filesystem of this container image, create a new
   477  directory, such as `f60c56784b83`, and initialize it with a snapshot of the
   478  parent image's root filesystem, so that the directory is identical to that
   479  of `c3167915dc9d`. NOTE: a copy-on-write or union filesystem can make this very
   480  efficient:
   481  
   482  ```
   483  f60c56784b83/
   484      etc/
   485          my-app-config
   486      bin/
   487          my-app-binary
   488          my-app-tools
   489  ```
   490  
   491  This example change is going add a configuration directory at `/etc/my-app.d`
   492  which contains a default config file. There's also a change to the
   493  `my-app-tools` binary to handle the config layout change. The `f60c56784b83`
   494  directory then looks like this:
   495  
   496  ```
   497  f60c56784b83/
   498      etc/
   499          my-app.d/
   500              default.cfg
   501      bin/
   502          my-app-binary
   503          my-app-tools
   504  ```
   505  
   506  This reflects the removal of `/etc/my-app-config` and creation of a file and
   507  directory at `/etc/my-app.d/default.cfg`. `/bin/my-app-tools` has also been
   508  replaced with an updated version. Before committing this directory to a
   509  changeset, because it has a parent image, it is first compared with the
   510  directory tree of the parent snapshot, `f60c56784b83`, looking for files and
   511  directories that have been added, modified, or removed. The following changeset
   512  is found:
   513  
   514  ```
   515  Added:      /etc/my-app.d/default.cfg
   516  Modified:   /bin/my-app-tools
   517  Deleted:    /etc/my-app-config
   518  ```
   519  
   520  A Tar Archive is then created which contains *only* this changeset: The added
   521  and modified files and directories in their entirety, and for each deleted item
   522  an entry for an empty file at the same location but with the basename of the
   523  deleted file or directory prefixed with `.wh.`. The filenames prefixed with
   524  `.wh.` are known as "whiteout" files. NOTE: For this reason, it is not possible
   525  to create an image root filesystem which contains a file or directory with a
   526  name beginning with `.wh.`. The resulting Tar archive for `f60c56784b83` has
   527  the following entries:
   528  
   529  ```
   530  /etc/my-app.d/default.cfg
   531  /bin/my-app-tools
   532  /etc/.wh.my-app-config
   533  ```
   534  
   535  Any given image is likely to be composed of several of these Image Filesystem
   536  Changeset tar archives.
   537  
   538  ## Combined Image JSON + Filesystem Changeset Format
   539  
   540  There is also a format for a single archive which contains complete information
   541  about an image, including:
   542  
   543   - repository names/tags
   544   - image configuration JSON file
   545   - all tar archives of each layer filesystem changesets
   546  
   547  For example, here's what the full archive of `library/busybox` is (displayed in
   548  `tree` format):
   549  
   550  ```
   551  .
   552  ├── 47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json
   553  ├── 5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a
   554  │   ├── VERSION
   555  │   ├── json
   556  │   └── layer.tar
   557  ├── a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198
   558  │   ├── VERSION
   559  │   ├── json
   560  │   └── layer.tar
   561  ├── manifest.json
   562  └── repositories
   563  ```
   564  
   565  There is a directory for each layer in the image. Each directory is named with
   566  a 64 character hex name that is deterministically generated from the layer
   567  information. These names are not necessarily layer DiffIDs or ChainIDs. Each of
   568  these directories contains 3 files:
   569  
   570   * `VERSION` - The schema version of the `json` file
   571   * `json` - The legacy JSON metadata for an image layer. In this version of
   572      the image specification, layers don't have JSON metadata, but in
   573      [version 1](v1.md), they did. A file is created for each layer in the
   574      v1 format for backward compatibility.
   575   * `layer.tar` - The Tar archive of the filesystem changeset for an image
   576     layer.
   577  
   578  Note that this directory layout is only important for backward compatibility.
   579  Current implementations use the paths specified in `manifest.json`.
   580  
   581  The content of the `VERSION` files is simply the semantic version of the JSON
   582  metadata schema:
   583  
   584  ```
   585  1.0
   586  ```
   587  
   588  The `repositories` file is another JSON file which describes names/tags:
   589  
   590  ```
   591  {  
   592      "busybox":{  
   593          "latest":"5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a"
   594      }
   595  }
   596  ```
   597  
   598  Every key in this object is the name of a repository, and maps to a collection
   599  of tag suffixes. Each tag maps to the ID of the image represented by that tag.
   600  This file is only used for backwards compatibility. Current implementations use
   601  the `manifest.json` file instead.
   602  
   603  The `manifest.json` file provides the image JSON for the top-level image, and
   604  optionally for parent images that this image was derived from. It consists of
   605  an array of metadata entries:
   606  
   607  ```
   608  [
   609    {
   610      "Config": "47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb.json",
   611      "RepoTags": ["busybox:latest"],
   612      "Layers": [
   613        "a65da33792c5187473faa80fa3e1b975acba06712852d1dea860692ccddf3198/layer.tar",
   614        "5f29f704785248ddb9d06b90a11b5ea36c534865e9035e4022bb2e71d4ecbb9a/layer.tar"
   615      ]
   616    }
   617  ]
   618  ```
   619  
   620  There is an entry in the array for each image.
   621  
   622  The `Config` field references another file in the tar which includes the image
   623  JSON for this image.
   624  
   625  The `RepoTags` field lists references pointing to this image.
   626  
   627  The `Layers` field points to the filesystem changeset tars.
   628  
   629  An optional `Parent` field references the imageID of the parent image. This
   630  parent must be part of the same `manifest.json` file.
   631  
   632  This file shouldn't be confused with the distribution manifest, used to push
   633  and pull images.
   634  
   635  Generally, implementations that support this version of the spec will use
   636  the `manifest.json` file if available, and older implementations will use the
   637  legacy `*/json` files and `repositories`.