Cloud Native 19 min read

Comprehensive Docker Guide: Introduction, Installation, Basic Commands, Dockerfile, and Image Publishing

This article provides a detailed overview of Docker, covering its origins, core concepts, advantages, installation steps, configuration of accelerators, essential command‑line usage, container lifecycle management, Dockerfile syntax for custom images, and how to publish images to public and private registries.

Java Captain
Java Captain
Java Captain
Comprehensive Docker Guide: Introduction, Installation, Basic Commands, Dockerfile, and Image Publishing

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.

Key use cases include automated packaging and deployment of web applications, continuous integration/testing pipelines, and flexible deployment of databases or other services in a service‑oriented environment.

Compared with physical machines and traditional virtual machines, Docker containers are lightweight, start in seconds, share the host kernel, and ensure consistent runtime environments, which simplifies migration across physical, virtual, cloud, or local platforms.

Docker’s three fundamental concepts are images, containers, and repositories, and its main advantages are higher resource utilization, rapid startup, environment consistency, streamlined CI/CD workflows, and easier migration.

Installation : Docker requires a 64‑bit CentOS 7+ kernel (≥ 3.10). Install with yum install docker , start with systemctl start docker , and verify with docker version . For faster image pulls in China, configure the DaoCloud accelerator using the provided curl command.

Basic Commands : The docker --help output lists options (e.g., --debug , -H , --tls ) and commands such as run , build , commit , ps , logs , push , pull , etc., each with a brief description.

Containers can be started in detached mode ( docker run -d … ) or interactively ( docker run -it … ). A stopped container can be restarted with docker start and accessed via docker exec -it .

To create a custom image, modify a running container (e.g., install vim ) and commit it with docker commit myrepo/custom-image , then verify with docker images .

External access to containerized services is achieved with port mapping using -p hostPort:containerPort or -P for random mapping; the host IP and mapped port can be used to reach the application.

Dockerfile : A Dockerfile is a plain‑text script that defines image layers. Typical instructions include FROM , LABEL , RUN , WORKDIR , ADD / COPY , ENV , EXPOSE , CMD , and ENTRYPOINT . Use RUN for installing packages, WORKDIR to set the working directory, and prefer COPY over ADD unless extraction is needed.

Advanced Dockerfile concepts cover VOLUME , EXPOSE , CMD , ENTRYPOINT , and the difference between shell and exec forms.

Publishing Images : Push images to Docker Hub after logging in ( docker login ) and tagging appropriately ( docker tag local-image username/repo ). For private registries, run the official registry image, configure /etc/docker/daemon.json with insecure-registries , reload the daemon, and push/pull using the private address.

Example : A Flask application is containerized with a simple Dockerfile that uses python:2.7 as the base, installs Flask, copies app.py , exposes port 8080, and runs the app. The image is built, run with port mapping, and optionally pushed to a private registry.

DockerdevopsContainerizationlinuxCommand-lineDockerfileImage Registry
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

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.