Docker Fundamentals: Core Command Line Operations
Inspecting Resources
Viewing Image Repositories
Retrieve a list of all image objects available locally.
docker images --all
Monitoring Active Containers
List currently running instances to verify status and obtain identifiers.
docker ps -a
The output displays the Container ID in the first column, which is required for subsequent operations.
Mdoifying Images
Committing Runtime Changes
Capture the current state of a container as a new image artifact. This is useful for saving temporary configurations or dependencies.
docker commit \
-m="Applied security patches" \
--author "dev-team@example.com" \
container-7f8a9b0c custom-app:v2.1
Parameters:
-m: Description string summarizing changes.--author: Email or name identifying the creator.container-id: Target idantifier from an active container.image-name:tag: Destination name and version tag for the new image.
Lifecycle Management
Instantiating Instances
Launch a new process based on a specific image with configuration overrides.
docker run -d \
--name web-service \
-v /opt/data:/var/www/html \
-p 3000:80 \
python:3.9-slim \
tail -f /dev/null
Configuration Breakdown:
-d: Detached mode (runs in background).--name: Assigns a human-readable alias (web-service).-v: Bind mounts host directory/opt/datainto container path/var/www/html.-p: Maps host port3000to container port80.- Image reference
python:3.9-slimspecifies the base environment.
Interactive Access
Enter the shell of a running instance for debugging or administration.
docker exec -it web-service bash
Termination and Removal
Stop a specific instance and purge its filesystem data.
docker stop web-service
docker rm web-service
Image Tagging and Cleanup
Renaming References
Update tags without duplicating underlying layers.
docker tag old-repo/app:v1 latest-staging/app:v1
Removing Artifacts
Force delete a untagged or referenced image layer.
docker rmi -f old-repo/app:v1