LinuxCommandLibrary

docker-container-commit

Create a new image from a container

TLDR

Create an image from a specific container

$ docker [[commit|container commit]] [container] [image]:[tag]
copy

Apply a CMD Dockerfile instruction to the created image
$ docker [[commit|container commit]] [[-c|--change]] "CMD [command]" [container] [image]:[tag]
copy

Apply an ENV Dockerfile instruction to the created image
$ docker [[commit|container commit]] [[-c|--change]] "ENV [name]=[value]" [container] [image]:[tag]
copy

Create an image with a specific author in the metadata
$ docker [[commit|container commit]] [[-a|--author]] "[author]" [container] [image]:[tag]
copy

Create an image with a specific comment in the metadata
$ docker [[commit|container commit]] [[-m|--message]] "[comment]" [container] [image]:[tag]
copy

Create an image without pausing the container during commit
$ docker [[commit|container commit]] [[-p|--pause]] false [container] [image]:[tag]
copy

Display help
$ docker [[commit|container commit]] --help
copy

SYNOPSIS

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

PARAMETERS

-a, --author string
    Author of the image (e.g., "Bill Murray <bill.murray@imaginary.com>")

-c, --change list
    Apply Dockerfile instructions to created image (e.g., CMD, ENV, EXPOSE)

-m, --message string
    Commit message describing changes

-p, --pause bool
    Pause container during commit (default true)

DESCRIPTION

The docker commit command creates a new Docker image from an existing container by capturing all filesystem changes made during the container's lifetime. This is particularly useful for debugging, quick prototyping, or saving intermediate states without a Dockerfile.

Specify a running or stopped container by ID or name, followed optionally by a repository name and tag for the new image (e.g., myimage:v1). By default, the container is paused during the commit process to ensure consistency, though this can be disabled.

Options allow customizing the commit: set an author name/email, add a descriptive message, apply Dockerfile-like changes (e.g., CMD, ENV, EXPOSE), or squash layers (deprecated). The resulting image includes the container's current state, including any modifications to files, installed packages, or configurations.

While convenient, docker commit is discouraged for production workflows as it creates opaque, non-reproducible images. Layers may bloat if large files are modified, and it's harder to track changes compared to layered builds via docker build. Always tag and push committed images for sharing.

CAVEATS

Avoid for production; produces non-reproducible, bloated images. Prefer Dockerfiles. Deprecated --squash option ignored in recent versions.

EXAMPLE

docker commit abc123 myimage:latest
docker commit -m "Added nginx" -a "John Doe" mycontainer myrepo/nginx:v1

OUTPUT

Returns new image ID/SHA (e.g., sha256:abc123...) or error if container not found.

HISTORY

Introduced in Docker 0.6 (2013); stabilized in Docker 1.0. Evolved with layer squashing (later deprecated) to optimize image size.

SEE ALSO

Copied to clipboard