Cloud Native 31 min read

Docker Beginner Guide: Installation, Core Concepts, Image & Container Management, Registry Setup, and Docker Compose

This comprehensive tutorial walks through Docker installation on CentOS 7, explains container fundamentals and differences from virtual machines, details image creation, repository management, container lifecycle commands, networking, data sharing, and demonstrates automated builds and orchestration using Maven and Docker Compose for a full Spring Cloud micro‑service stack.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Docker Beginner Guide: Installation, Core Concepts, Image & Container Management, Registry Setup, and Docker Compose

This article provides a step‑by‑step introduction to Docker, covering installation, basic commands, core concepts, and advanced usage scenarios.

1. Docker Installation and First Run

Prepare a CentOS 7 64‑bit system with kernel version 3.10 or higher, then install Docker with:

yum -y install docker-io

Start the daemon:

service docker start

Run a test Nginx container:

docker run -p 80:80 -d nginx

2. Docker Theory

Docker uses lightweight containers (similar to shipping containers) instead of full virtual machines, providing process‑level isolation, fast startup, and low overhead.

Key components:

Docker daemon (dockerd) : Manages images, containers, networks, and volumes.

REST API : Enables client‑server communication.

Docker CLI : Command‑line interface for interacting with the daemon.

Image : Read‑only template that can be layered.

Container : Runtime instance created from an image.

Registry : Stores and distributes images (Docker Hub, Alibaba Cloud, private registries).

3. Image Management

Common image commands:

docker images          # list local images
docker search mysql   # search remote registry
docker pull mysql:5.7 # download image
docker rmi
# remove image

Configure a mirror for faster pulls (CentOS example):

{
  "registry-mirrors": ["https://uqxmqcrw.mirror.aliyuncs.com"]
}

4. Dockerfile Basics

A Dockerfile defines how to build a custom image. Example:

# Base image
FROM java:8
# Maintainer
MAINTAINER jackly
# Add application JAR
ADD eureka-server-0.0.1-SNAPSHOT.jar /app/service/eureka/data/app.jar
# Expose port
EXPOSE 8761
# Startup command
ENTRYPOINT ["java","-jar","/app/service/eureka/data/app.jar"]

Build and run the image:

docker build -t registry-jackly/eureka-server:1.0.0 .
docker run -d -p 8761:8761 --name=eureka registry-jackly/eureka-server:1.0.0

5. Container Lifecycle & Management

Typical container commands:

docker run -d -p 5000:5000 --name=registry-local-jackly registry
docker ps -a               # list containers
docker stop
docker start
docker exec -it
/bin/bash   # interactive shell
docker commit -m "add ll" -a "jackly"
registry-jackly/eureka-server:2.0.0

6. Networking

Expose services with -p hostPort:containerPort or random ports with -P . Containers on the same user‑defined network can communicate via their names.

7. Data Sharing (Volumes)

Mount host directories into containers:

docker run -d -p 8761:8761 -v /app/service/eureka/logs:/opt/data --name=eureka registry-jackly/eureka-server:2.0.0

Note: VOLUME in a Dockerfile creates an anonymous volume; the host path is managed by Docker under /var/lib/docker/volumes/ .

8. Private Registry Setup

Generate RSA certificates, run a registry container, and optionally a web UI:

# Generate cert
openssl req -new -newkey rsa:4096 -days 365 -subj "/CN=localhost" -nodes -x509 -keyout conf/auth.key -out conf/auth.cert
# Run registry
docker run -v /app/registry-jackly/conf/registry-jackly.yml:/etc/docker/registry/config.yml:ro \
  -v /app/registry-jackly/conf/auth.cert:/etc/docker/registry/auth.cert:ro \
  -p 5000:5000 --name registry-docker -d registry

9. Maven Docker Plugin

Configure the Spotify Docker Maven plugin to build and push images directly from the Maven lifecycle.

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>1.1.1</version>
  <configuration>
    <registryUrl>registry-docker:5000</registryUrl>
    <dockerHost>http://registry-docker:2375</dockerHost>
    <imageName>registry-docker:5000/${project.artifactId}:${project.version}</imageName>
    <baseImage>java:8</baseImage>
    <entryPoint>["java","-jar","/${project.build.finalName}.jar"]</entryPoint>
    <pushImage>true</pushImage>
  </configuration>
</plugin>

10. Docker Compose for a Spring Cloud Stack

Define services (eureka, config, zipkin, ELK, microservices, MySQL, Zuul) in separate docker-compose.yml files and launch them with:

docker-compose -f docker-compose-eureka.yml up -d
docker-compose -f docker-compose-config.yml up -d
... (other services)

Example of a service definition:

version: '3'
services:
  eureka:
    container_name: eureka
    image: registry-docker:5000/eureka-server:1.0.0
    ports:
      - "8761:8761"
    volumes:
      - /app/service/eureka/logs:/opt/data
    privileged: true
    networks:
      - default
networks:
  default:
    external:
      name: dockernet

After deployment you can access the registry UI, ELK Kibana, Zipkin UI, and the various microservice endpoints (e.g., http:// :8761/ , http:// :8083/product/findAllProduct ).

DockerDevOpsContainerizationDocker ComposeImage Management
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

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.