Cloud Native 14 min read

Docker Basics: Installation, Core Commands, and Dockerfile Guide

This article provides a comprehensive introduction to Docker, covering its underlying technology, reasons for adoption, step‑by‑step installation on CentOS, essential image and container commands, detailed Dockerfile instructions, and practical examples for building and running a Spring Boot application.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Docker Basics: Installation, Core Commands, and Dockerfile Guide

Docker is a lightweight containerization platform built with Go, leveraging Linux kernel features such as cgroups, namespaces, and UnionFS to isolate processes, making each container a regular process on the host rather than a full virtual machine.

Using Docker ensures consistent runtime environments across development, testing, and production, speeding up packaging, testing, and deployment while reducing the code‑to‑run cycle.

Installation on CentOS

Before installing, verify the kernel version (>=3.10) with uname -r. Update the system, remove any old Docker packages, and install required utilities:

yum update<br/>yum remove docker docker-common docker-selinux docker-engine<br/>yum install -y yum-utils device-mapper-persistent-data lvm2

Add the Docker repository:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE, start the service, and verify the installation:

yum install docker-ce<br/>systemctl start docker<br/>docker run hello-world

Important Docker Commands

Image Management

Search, pull, list, remove, and build images using commands such as docker search nginx, docker pull nginx, docker images, docker rmi hello-world, and docker build.

Container Management

Create and run containers with docker run (options: -d background, -p port mapping, -v volume mount, --rm auto‑remove, --name naming). List containers with docker ps -a, stop with docker stop <id>, start with docker start <id>, restart with docker restart <id>, exec into a container using docker exec -it <id> /bin/bash, remove with docker rm <id>, and copy files via docker cp.

Dockerfile Instructions

A Dockerfile defines how to build an image. Key directives include: FROM – base image (e.g., openjdk:8-jdk-alpine) RUN – execute commands (shell or exec form) CMD – default container command ENTRYPOINT – container entry point COPY / ADD – copy files into the image EXPOSE – declare listening ports ENV – set environment variables VOLUME – define mount points LABEL – add metadata

Example Dockerfile for a Spring Boot JAR:

FROM openjdk:8-jdk-alpine<br/>VOLUME /tmp<br/>EXPOSE 8080<br/>COPY docker-demo.jar app.jar<br/>ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Build and run the image:

docker build -t springboot:v1.0 .<br/>docker run -v /app/docker/logs:/logs -p 8080:8080 --rm --name springboot springboot:v1.0

Access the application at http://<host>:8080/say and monitor logs with tail -f /app/docker/logs/docker-demo-info.log.

Conclusion

The guide consolidates frequently used Docker commands and Dockerfile directives, providing practical examples that help readers quickly master containerization for development and deployment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpscontainerizationLinuxDockerfileCommand-Line
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

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.