Master Docker Basics: Images, Containers, Repositories & Essential Commands
This article explains Docker's core concepts—images, containers, and repositories—highlights its six key advantages over virtual machines, provides essential command‑line examples, and discusses common Java‑related pitfalls and solutions when running Java applications inside Docker containers.
Background Knowledge
Docker, first released in 2013, has become as ubiquitous as MySQL and Redis. It is an open‑source container engine that lets you package applications and their environments (e.g., JDK, Java programs) and run them on any Linux host.
Docker revolves around three fundamental concepts:
Image : a read‑only filesystem containing the program, libraries, resources, and configuration needed at runtime. Images are immutable after they are built.
Container : a runnable instance of an image. Containers can be created, started, stopped, paused, and removed.
Repository : a storage location for images, such as Docker Hub.
Before containers, deploying Java applications required manually installing JDK, configuring Tomcat, and tuning JVM parameters on each server, a time‑consuming process. Virtual machines offered a way to bundle environments but consumed excessive memory and CPU because they run full operating systems.
Linux Containers (LXC) introduced lightweight, process‑level isolation, and Docker built on LXC to provide a user‑friendly interface, quickly gaining popularity.
Key Advantages of Docker
Lightweight : shares the host kernel instead of running a full OS.
Flexible : can containerize complex applications.
Portable : build locally and deploy anywhere.
Isolated & Upgradable : containers are self‑contained and can be upgraded without affecting others.
Scalable : easily replicate containers across data centers.
Secure : strong isolation without extra configuration.
Key Analysis
What are Docker's common commands?
What issues might arise when running Java programs in Docker?
Knowledge Expansion
Docker Common Commands
Check Docker version: $ docker --version Search and pull images from Docker Hub (e.g., Redis): $ docker pull redis List downloaded images: $ docker images Create and run a container: $ docker run --name myredis -d redis View running containers: $ docker ps Execute a command inside a container (e.g., Redis CLI): $ docker exec -it myredis redis-cli Other useful commands:
Stop container: docker stop <em>container_name</em> Start container: docker start <em>container_name</em> Remove container: docker rm <em>container_name</em> Remove image: docker rmi <em>image_name</em> List all containers: docker ps -a Copy files between host and container:
docker cpPotential Docker Issues for Java
Older Java versions (e.g., JDK 8u131) may not recognize Docker’s resource limits, causing unexpected termination or excessive thread creation.
Without explicit JVM heap and direct‑memory settings, Java may request more memory than the container allows, triggering Docker’s OOM killer.
Early Java runtimes also misinterpret CPU resources, leading ParallelStreams or ForkJoinPool to create more threads than available cores, degrading performance.
Example of ParallelStreams:
List<Integer> numbers = Arrays.asList(1,2,3,4,5,6,7,8,9);
numbers.parallelStream().forEach(count -> {
System.out.println("val:" + count);
});ForkJoinPool obtains the core count via Runtime.getRuntime().availableProcessors():
private static ForkJoinPool makeCommonPool() {
if (parallelism < 0 &&
(parallelism = Runtime.getRuntime().availableProcessors() - 1) <= 0)
parallelism = 1;
if (parallelism > MAX_CAP)
parallelism = MAX_CAP;
return new ForkJoinPool(parallelism, factory, handler, LIFO_QUEUE,
"ForkJoinPool.commonPool-worker-");
}Solution: upgrade to a newer Java version (e.g., Java 10) that understands Docker limits, or manually set JVM options such as heap size and limit ForkJoinPool threads, e.g.:
-Djava.util.concurrent.ForkJoinPool.common.parallelism=8Conclusion
The article introduced Docker’s core concepts—images, containers, and repositories—outlined its six major benefits, presented essential Docker commands, and highlighted Java‑specific issues in older JDKs when running inside containers, offering upgrade and configuration remedies.
Signed-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
