docker container commit
Description | Create a new image from a container's changes |
---|---|
Usage | docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] |
Aliases An alias is a short or memorable alternative for a longer command. | docker commit |
Description
It can be useful to commit a container's file changes or settings into a newimage. This lets you debug a container by running an interactive shell, orexport a working dataset to another server.
Commits do not include any data contained in mounted volumes.
By default, the container being committed and its processes will be pausedwhile the image is committed. This reduces the likelihood of encountering datacorruption during the process of creating the commit. If this behavior isundesired, set the--pause
option to false.
The--change
option will applyDockerfile
instructions to the image that'screated. SupportedDockerfile
instructions:CMD
|ENTRYPOINT
|ENV
|EXPOSE
|LABEL
|ONBUILD
|USER
|VOLUME
|WORKDIR
Options
Option | Default | Description |
---|---|---|
-a, --author | Author (e.g.,John Hannibal Smith <hannibal@a-team.com> ) | |
-c, --change | Apply Dockerfile instruction to the created image | |
-m, --message | Commit message | |
-p, --pause | true | Pause container during commit |
Examples
Commit a container
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton$ docker commit c3f279d17e0a svendowideit/testimage:version3f5283438590d$ docker imagesREPOSITORY TAG ID CREATED SIZEsvendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
Commit a container with new configurations (--change)
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky197387f1b436 ubuntu:24.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:version3f5283438590d$ 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 newCMD
andEXPOSE
instructions
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton$ docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c"EXPOSE 80" c3f279d17e0a svendowideit/testimage:version4f5283438590d$ docker run -d svendowideit/testimage:version489373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES89373736e2e7 testimage:version4 "apachectl -DFOREGROU" 3 seconds ago Up 2 seconds 80/tcp distracted_fermatc3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
[8]ページ先頭
©2009-2025 Movatter.jp