Step‑by‑Step Guide to Pulling, Building, Committing, and Transferring Docker Images
This article explains how to obtain base images, use Docker Hub, pull images with docker pull, create images via Dockerfile, container commits, tag and push images, and import/export images between hosts using docker save and docker load, providing complete command examples and best‑practice tips.
In most cases we create Docker images based on an existing base image (for example, a minimal CentOS, Ubuntu, or Debian) which we call a base image .
The minimal CentOS image is provided by Docker Hub maintainers; creating it is straightforward for Docker staff but not for end users.
Docker Hub
Docker Hub is a cloud‑based registry service that lets you link to code repositories, build and test images, store manually pushed images, and connect to Docker Cloud for deployment. It provides centralized image discovery, distribution, change management, user and team collaboration, and workflow automation.
Key features of Docker Hub include:
Image repository
Search and pull images from community and official libraries; manage, push, and pull images from private repositories you have access to
Automated builds
Automatic image creation when source code changes
Web documentation
Webhooks to trigger actions after a successful push
Organizations and work‑groups for repository access control
GitHub and Bitbucket integration
Adding Docker images to your current workflow
Getting Docker Images
To pull an image from a remote registry (including your own Docker registry) use the docker pull command:
docker pull [registry][:port]/[namespace]/[image]:[tag]
Example: [root@localhost ~]# docker pull busybox After pulling you can run a container:
[root@localhost ~]# docker run --name bi -it busyboxTo view the default process of a container, use docker inspect:
[root@localhost ~]# docker inspect biImage Generation
Images can be generated via:
Dockerfile
Commit from a running container
Docker Hub automated builds
Creating an Image from a Container
Modify a running container and commit it as a new image:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Common options:
--author, -a Author (e.g., "John Smith <[email protected]>")
-c, --change Apply Dockerfile instructions to the created image
-m, --message Commit message
-p, --pause Pause container during commit (default: true)Example workflow:
[root@localhost ~]# docker pull busybox
[root@localhost ~]# docker run --name bi -it busybox
/root@localhost ~# echo 'nihao' > data/index.html
[root@localhost ~]# docker commit -p bi
sha256:b726393438ac...<br/>[root@localhost ~]# docker tag b726393438ac luojialong123/v1
[root@localhost ~]# docker push luojialong123/v1When the default container process is sh but you need an HTTP server, set the command to /bin/httpd -f -h /data during commit.
Image Import and Export
To transfer an image between two hosts without pushing to a registry, export it to a file with docker save and import it on the target host with docker load.
# Export on host 1
docker save -o busybox.tar luojialong123/v1
# Transfer the file to host 2
# Import on host 2
docker load -i busybox.tarAfter loading, the image appears in docker images and can be used to create containers.
Example of creating a container from the imported image and exposing an HTTP service:
# Run container with port mapping
docker run --name t2 -d -p 80:80 luojialong123/v2
# Verify the service
curl 172.17.0.3Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
