github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/container_commit.md (about)

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