2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "commit"
|
|
|
|
description: "The commit command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "commit, file, changes"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-10-19 13:25:45 -04:00
|
|
|
<!-- This file is maintained within the docker/docker Github
|
|
|
|
repository at https://github.com/docker/docker/. Make all
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
will be rejected.
|
|
|
|
-->
|
|
|
|
|
2015-06-21 16:41:38 -04:00
|
|
|
# commit
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
```markdown
|
|
|
|
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
Create a new image from a container's changes
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
Options:
|
|
|
|
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
|
|
|
|
-c, --change value Apply Dockerfile instruction to the created image (default [])
|
|
|
|
--help Print usage
|
|
|
|
-m, --message string Commit message
|
|
|
|
-p, --pause Pause container during commit (default true)
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
|
|
|
|
2015-06-21 16:41:38 -04:00
|
|
|
It can be useful to commit a container's file changes or settings into a new
|
2017-04-10 09:12:19 -04:00
|
|
|
image. This allows you to debug a container by running an interactive shell, or to
|
2015-06-21 16:41:38 -04:00
|
|
|
export a working dataset to another server. Generally, it is better to use
|
|
|
|
Dockerfiles to manage your images in a documented and maintainable way.
|
2016-05-11 09:15:50 -04:00
|
|
|
[Read more about valid image names and tags](tag.md).
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2015-06-17 09:04:41 -04:00
|
|
|
The commit operation will not include any data contained in
|
|
|
|
volumes mounted inside the container.
|
|
|
|
|
2015-06-21 16:41:38 -04:00
|
|
|
By default, the container being committed and its processes will be paused
|
|
|
|
while the image is committed. This reduces the likelihood of encountering data
|
|
|
|
corruption during the process of creating the commit. If this behavior is
|
2016-02-16 22:54:45 -05:00
|
|
|
undesired, set the `--pause` option to false.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
The `--change` option will apply `Dockerfile` instructions to the image that is
|
|
|
|
created. Supported `Dockerfile` instructions:
|
2015-07-09 12:57:42 -04:00
|
|
|
`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`LABEL`|`ONBUILD`|`USER`|`VOLUME`|`WORKDIR`
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Commit a container
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|
|
|
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
|
|
|
|
|
|
|
$ docker commit c3f279d17e0a svendowideit/testimage:version3
|
|
|
|
|
|
|
|
f5283438590d
|
|
|
|
|
|
|
|
$ docker images
|
|
|
|
|
|
|
|
REPOSITORY TAG ID CREATED SIZE
|
|
|
|
svendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
|
|
|
|
```
|
|
|
|
|
|
|
|
### Commit a container with new configurations
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker ps
|
|
|
|
|
2017-03-07 16:33:30 -05:00
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
2017-02-07 18:42:48 -05:00
|
|
|
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
|
|
|
|
|
|
|
$ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
|
|
|
|
|
|
|
|
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
|
|
|
|
|
|
|
|
$ docker commit --change "ENV DEBUG true" c3f279d17e0a svendowideit/testimage:version3
|
|
|
|
|
|
|
|
f5283438590d
|
|
|
|
|
|
|
|
$ docker inspect -f "{{ .Config.Env }}" f5283438590d
|
|
|
|
|
|
|
|
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Commit a container with new `CMD` and `EXPOSE` instructions
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|
|
|
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
|
|
|
|
|
|
|
$ docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a svendowideit/testimage:version4
|
|
|
|
|
|
|
|
f5283438590d
|
|
|
|
|
|
|
|
$ docker run -d svendowideit/testimage:version4
|
|
|
|
|
|
|
|
89373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0
|
|
|
|
|
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|
|
|
89373736e2e7 testimage:version4 "apachectl -DFOREGROU" 3 seconds ago Up 2 seconds 80/tcp distracted_fermat
|
|
|
|
c3f279d17e0a ubuntu:12.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:12.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
|
|
|
```
|