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