github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/docs/reference/commandline/commit.md (about)

     1  ---
     2  title: "commit"
     3  description: "The commit command description and usage"
     4  keywords: "commit, file, changes"
     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  # commit
    17  
    18  ```markdown
    19  Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
    20  
    21  Create a new image from a container's changes
    22  
    23  Options:
    24    -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
    25    -c, --change value     Apply Dockerfile instruction to the created image (default [])
    26        --help             Print usage
    27    -m, --message string   Commit message
    28    -p, --pause            Pause container during commit (default true)
    29  ```
    30  
    31  ## Description
    32  
    33  It can be useful to commit a container's file changes or settings into a new
    34  image. This allows you debug a container by running an interactive shell, or to
    35  export a working dataset to another server. Generally, it is better to use
    36  Dockerfiles to manage your images in a documented and maintainable way.
    37  [Read more about valid image names and tags](tag.md).
    38  
    39  The commit operation will not include any data contained in
    40  volumes mounted inside the container.
    41  
    42  By default, the container being committed and its processes will be paused
    43  while the image is committed. This reduces the likelihood of encountering data
    44  corruption during the process of creating the commit.  If this behavior is
    45  undesired, set the `--pause` option to false.
    46  
    47  The `--change` option will apply `Dockerfile` instructions to the image that is
    48  created.  Supported `Dockerfile` instructions:
    49  `CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`LABEL`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR`
    50  
    51  ## Examples
    52  
    53  ### Commit a container
    54  
    55  ```bash
    56  $ docker ps
    57  
    58  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
    59  c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
    60  197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton
    61  
    62  $ docker commit c3f279d17e0a  svendowideit/testimage:version3
    63  
    64  f5283438590d
    65  
    66  $ docker images
    67  
    68  REPOSITORY                        TAG                 ID                  CREATED             SIZE
    69  svendowideit/testimage            version3            f5283438590d        16 seconds ago      335.7 MB
    70  ```
    71  
    72  ### Commit a container with new configurations
    73  
    74  ```bash
    75  {% raw %}
    76  $ docker ps
    77  
    78  ICONTAINER ID       IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
    79  c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
    80  197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton
    81  
    82  $ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
    83  
    84  [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
    85  
    86  $ docker commit --change "ENV DEBUG true" c3f279d17e0a  svendowideit/testimage:version3
    87  
    88  f5283438590d
    89  
    90  $ docker inspect -f "{{ .Config.Env }}" f5283438590d
    91  
    92  [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
    93  {% endraw %}
    94  ```
    95  
    96  ### Commit a container with new `CMD` and `EXPOSE` instructions
    97  
    98  ```bash
    99  $ docker ps
   100  
   101  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
   102  c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
   103  197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton
   104  
   105  $ docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a  svendowideit/testimage:version4
   106  
   107  f5283438590d
   108  
   109  $ docker run -d svendowideit/testimage:version4
   110  
   111  89373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0
   112  
   113  $ docker ps
   114  
   115  CONTAINER ID        IMAGE               COMMAND                 CREATED             STATUS              PORTS              NAMES
   116  89373736e2e7        testimage:version4  "apachectl -DFOREGROU"  3 seconds ago       Up 2 seconds        80/tcp             distracted_fermat
   117  c3f279d17e0a        ubuntu:12.04        /bin/bash               7 days ago          Up 25 hours                            desperate_dubinsky
   118  197387f1b436        ubuntu:12.04        /bin/bash               7 days ago          Up 25 hours                            focused_hamilton
   119  ```