Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Creating Custom Docker Images via Container Commits and Registry Distribution

Tech 1

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.

  1. 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> .
    
  2. Authenticate with the Registry: Establish a trusted session before transferring data:

    docker login
    

    Supply credentials when prompted to authorize repository write access.

  3. Upload to the Repository: Transfer the compiled image to the remote registry:

    docker push <hub_username>/<artifact_name>:<release_tag>
    
  4. 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.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.