Cloud Native 20 min read

Docker Overview: Installation, Basic Commands, Image Management and Dockerfile Usage

This article provides a comprehensive introduction to Docker, covering its origin, core concepts, application scenarios, differences from physical machines and virtual machines, installation steps, essential commands, container lifecycle management, Dockerfile creation, image customization, registry publishing, and a practical Flask example.

Top Architect
Top Architect
Top Architect
Docker Overview: Installation, Basic Commands, Image Management and Dockerfile Usage

Docker was originally an internal project started by Solomon Hykes at dotCloud and open‑sourced in March 2013 under the Apache 2.0 license; it is written in Go and provides a simple interface for Linux container management.

Application scenarios include automated packaging and deployment of web applications, continuous integration/continuous delivery pipelines, and deployment/adjustment of databases or other services in a service‑oriented environment.

Differences among physical machines, virtual machines, and Docker containers are illustrated with three images (physical host, VM, Docker container).

Docker’s three core concepts are image, container, and repository. The advantages of Docker containers are:

Higher resource utilization because containers share the host kernel without the overhead of a full OS.

Fast startup time (seconds or milliseconds) compared with minutes for traditional VMs.

Consistent runtime environment, eliminating "works on my machine" issues.

Facilitates continuous delivery and deployment through Dockerfiles and CI systems.

Simplifies migration across physical hosts, VMs, public or private clouds.

Installation requires CentOS 7 (64‑bit) with kernel ≥ 3.10. The community edition can be installed with the following commands:

# yum install docker
systemctl start docker
systemctl status docker
docker version

For faster image downloads in China, the DaoCloud accelerator can be configured with a single command:

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://95822026.m.daocloud.io

Basic Docker commands are listed with brief explanations (attach, build, commit, cp, create, diff, events, exec, export, history, images, import, info, inspect, kill, load, login, logout, logs, pause, port, ps, pull, push, rename, restart, rm, rmi, run, save, search, start, stats, stop, tag, top, unpause, version, wait). Example usage:

docker --help

Starting containers can be done in two ways:

# Run a container in background
docker run -d centos /bin/sh -c "while true; do echo running; sleep 1; done"
# Run an interactive bash session
docker run --name mydocker -it centos /bin/bash

When a container is started, Docker checks for the image locally, pulls it if missing, creates a writable layer, configures networking, assigns an IP, and finally executes the user‑specified command.

To restart a stopped container:

# List containers
docker ps -a
# Start a specific container
docker start
# Attach interactively
docker exec -it
/bin/bash

Committing a container to create a custom image (e.g., installing vim inside a CentOS container) is demonstrated with docker commit and subsequent docker images inspection.

Exposing containers to the outside world uses the -p or -P flags for port mapping, as shown with a simple webapp example.

Dockerfile customization is explained: each instruction creates a new image layer. Common directives include FROM , LABEL , RUN , WORKDIR , ADD , COPY , ENV , EXPOSE , CMD , and ENTRYPOINT . Differences between shell and exec forms are highlighted.

Publishing images to Docker Hub requires logging in, tagging the image with the repository name, and pushing it. Private registries can be run using the official registry image, with volume mounting and HTTP configuration for insecure registries.

Practical example : a Flask application is containerized. The Dockerfile uses a Python 2.7 base image, installs Flask, copies app.py , sets the work directory, exposes port 8080, and defines the default command. The image is built, run with port mapping, and optionally pushed to a private registry.

-END-

DockerdevopsContainerizationLinuxDockerfileImage Registry
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.