github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/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 $ docker ps 76 77 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 78 c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky 79 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton 80 81 $ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a 82 83 [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] 84 85 $ docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3 86 87 f5283438590d 88 89 $ docker inspect -f "{{ .Config.Env }}" f5283438590d 90 91 [HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true] 92 ``` 93 94 ### Commit a container with new `CMD` and `EXPOSE` instructions 95 96 ```bash 97 $ docker ps 98 99 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 100 c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky 101 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton 102 103 $ docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a svendowideit/testimage:version4 104 105 f5283438590d 106 107 $ docker run -d svendowideit/testimage:version4 108 109 89373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0 110 111 $ docker ps 112 113 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 114 89373736e2e7 testimage:version4 "apachectl -DFOREGROU" 3 seconds ago Up 2 seconds 80/tcp distracted_fermat 115 c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky 116 197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton 117 ```