2015-06-21 16:41:38 -04:00
|
|
|
# commit
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
<!---MARKER_GEN_START-->
|
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
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
### Aliases
|
|
|
|
|
|
|
|
`docker container commit`, `docker commit`
|
|
|
|
|
|
|
|
### Options
|
|
|
|
|
|
|
|
| Name | Type | Default | Description |
|
|
|
|
|:---------------------------------------|:---------|:--------|:-----------------------------------------------------------|
|
|
|
|
| `-a`, `--author` | `string` | | Author (e.g., `John Hannibal Smith <hannibal@a-team.com>`) |
|
|
|
|
| [`-c`](#change), [`--change`](#change) | `list` | | Apply Dockerfile instruction to the created image |
|
|
|
|
| `-m`, `--message` | `string` | | Commit message |
|
|
|
|
| `-p`, `--pause` | | | Pause container during commit |
|
|
|
|
|
cli: use custom annotation for aliases
Cobra allows for aliases to be defined for a command, but only allows these
to be defined at the same level (for example, `docker image ls` as alias for
`docker image list`). Our CLI has some commands that are available both as a
top-level shorthand as well as `docker <object> <verb>` subcommands. For example,
`docker ps` is a shorthand for `docker container ps` / `docker container ls`.
This patch introduces a custom "aliases" annotation that can be used to print
all available aliases for a command. While this requires these aliases to be
defined manually, in practice the list of aliases rarely changes, so maintenance
should be minimal.
As a convention, we could consider the first command in this list to be the
canonical command, so that we can use this information to add redirects in
our documentation in future.
Before this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
...
With this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
docker image ls, docker image list, docker images
Options:
-a, --all Show all images (default hides intermediate images)
...
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-06-28 04:52:25 -04:00
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
<!---MARKER_GEN_END-->
|
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
|
2023-12-13 09:16:56 -05:00
|
|
|
image. This lets you debug a container by running an interactive shell, or
|
|
|
|
export a working dataset to another server.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2023-12-13 09:16:56 -05:00
|
|
|
Commits do not include any data contained in mounted volumes.
|
2015-06-17 09:04:41 -04:00
|
|
|
|
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
|
2023-12-13 09:16:56 -05:00
|
|
|
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
|
|
|
|
2023-12-13 09:16:56 -05:00
|
|
|
The `--change` option will apply `Dockerfile` instructions to the image that's
|
|
|
|
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
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
2022-06-06 09:02:58 -04:00
|
|
|
c3f279d17e0a ubuntu:22.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:22.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
2017-02-07 18:42:48 -05:00
|
|
|
|
|
|
|
$ docker commit c3f279d17e0a svendowideit/testimage:version3
|
|
|
|
|
|
|
|
f5283438590d
|
|
|
|
|
|
|
|
$ docker images
|
|
|
|
|
|
|
|
REPOSITORY TAG ID CREATED SIZE
|
|
|
|
svendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
|
|
|
|
```
|
|
|
|
|
2023-01-06 13:28:29 -05:00
|
|
|
### <a name="change"></a> Commit a container with new configurations (--change)
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker ps
|
|
|
|
|
2017-03-07 16:33:30 -05:00
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
2022-06-06 09:02:58 -04:00
|
|
|
c3f279d17e0a ubuntu:22.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:22.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
2017-02-07 18:42:48 -05:00
|
|
|
|
|
|
|
$ docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
|
|
|
|
|
|
|
|
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
|
|
|
|
|
2020-09-23 06:42:17 -04:00
|
|
|
$ docker commit --change "ENV DEBUG=true" c3f279d17e0a svendowideit/testimage:version3
|
2017-02-07 18:42:48 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-02-07 18:42:48 -05:00
|
|
|
$ docker ps
|
|
|
|
|
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
2022-06-06 09:02:58 -04:00
|
|
|
c3f279d17e0a ubuntu:22.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:22.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
2017-02-07 18:42:48 -05:00
|
|
|
|
|
|
|
$ 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
|
2022-06-06 09:02:58 -04:00
|
|
|
c3f279d17e0a ubuntu:22.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
|
|
|
|
197387f1b436 ubuntu:22.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
|
2017-02-07 18:42:48 -05:00
|
|
|
```
|