Creating Custom Docker Images via Container Commits and Registry Distribution
The docker commit instruction captures the current filesystem state of an active container and packages it into a new image layer. This mechanism operates similarly to version control by preserving manual modifications, installed packages, and configuration adjustments without requiring a Dockerfile rebuild.
docker commit --message="Snapshot description" --author="DevOps Team" <active_container_id> <target_repository>:<semantic_version>
Practical Implementation
When a base distribution lacks required application assets, administrators can deploy a container, manually inject files, and snapshot the environment for reuse.
# Launch a standard Apache HTTPD instance in detached mode
$ docker run -d --name web-srv -p 8080:80 httpd
# Access the runtime to modify the document root
$ docker exec -it web-srv /bin/sh
/usr/local/apache2/htdocs$ echo "<h1>Custom Environment</h1>" > index.html
$ exit
# Package the modified runtime into a distributable image
$ docker commit -a "engineering" -m "Deployed custom landing page" web-srv httpd-custom:v2.1
sha256:a1b2c3d4e5f67890abcdef1234567890abcdef1234567890abcdef1234567890
This workflow functions identically to virtual machine snapshots, allowing operators to freeze a specific runtime state. Once committed, the artifact behaves exactly like any standard registry image, eliminating repetitive initialization steps.
Distributing Artifacts via Container Registries
Sharing custom images across infrastructure requires pushing the local build to a centralized registry like Docker Hub. The distribution pipeline involves construction, authentication, upload, and retrieval.
-
Construct the Image: Define the environment via a
Dockerfile. The following specification builds a lightweight web server on a Alpine base:FROM alpine:3.18 RUN apk update && apk add nginx EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]Compile the definition into a tagged artifact:
docker build -t <hub_username>/<artifact_name>:<release_tag> . -
Authenticate with the Registry: Establish a trusted session before transferring data:
docker loginSupply credentials when prompted to authorize repository write access.
-
Upload to the Repository: Transfer the compiled image to the remote registry:
docker push <hub_username>/<artifact_name>:<release_tag> -
Retreive on Remote Hosts: Fetch the distributed artifact on any Docker-enabled node:
docker pull <hub_username>/<artifact_name>:<release_tag>Verify that the repository path and version tags match the original push operation to prevent resolution errors during deployment.