Master Docker: Core Concepts, Commands, and Java Compatibility Issues
This article explains Docker's evolution, core components (image, container, repository), six key advantages, essential command-line usage, and the challenges older Java versions face within Docker containers, offering practical solutions and best‑practice tips.
Background Knowledge
Docker has grown since 2013 and is now as popular as MySQL and Redis.
Docker is an open‑source container engine that packages applications and their environment, allowing them to run on any Linux host.
Docker has three key concepts:
Image : a read‑only filesystem that contains the program, libraries, resources and configuration needed to run a container.
Container : a runnable instance of an image; it can be created, started, stopped, removed, etc.
Repository : a storage location for images, e.g., Docker Hub.
Before Docker, deploying a Java program required installing JDK, configuring Tomcat, and repeating the process on each server, which was time‑consuming.
Virtual machines allowed bundling an OS image, but they consume a lot of memory and CPU because they run a full OS.
Linux Containers (LXC) provide process‑level isolation with lower overhead and faster startup.
Docker builds on LXC, offering a convenient API and quickly becoming popular. Docker vs VM comparison is shown below.
Docker’s six advantages:
Lightweight : shares the host kernel instead of a full OS.
Flexible : can containerize complex applications.
Portable : build locally and deploy anywhere.
Isolated and upgrade‑friendly : containers are self‑contained and can be upgraded without affecting others.
Scalable : can add and distribute container replicas across a data center.
Secure : provides strong isolation without extra configuration.
Key Analysis
Common Docker commands.
Potential issues when running Java programs in Docker.
Extended Knowledge
Common Docker Commands
After installing Docker Desktop, run docker --version to see the version.
Search for images on Docker Hub, e.g., Redis, and pull them:
$ docker pull redis
Using default tag: latest
latest: Pulling from library/redis
Digest: sha256:800f2587bf3376cb01e6307afe599ddce9439deafbd4fb8562829da96085c9c5
Status: Image is up to date for redis:latest
docker.io/library/redis:latestList downloaded images:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 235592615444 13 days ago 104MBCreate and run a container:
$ docker run --name myredis -d redis
22f560251e68b5afb5b7b52e202dcb3d47327f2136700d5a17bca7e37fc486bfShow running containers:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22f560251e68 redis "docker-entrypoint.s…" About a minute ago Up About a minute 6379/tcp myredisConnect to Redis:
$ docker exec -it myredis redis-cli 127.0.0.1:6379>Other useful commands:
Stop container: docker stop CONTAINER_NAME Start container: docker start CONTAINER_NAME Remove container: docker rm CONTAINER_NAME Remove image: docker rmi IMAGE_NAME List all containers: docker ps -a Copy files: docker cp CONTAINER:PATH HOST_PATH and vice versa.
Potential Docker Issues with Java
Older JDK versions (e.g., JDK 8u131) may not recognize Docker limits, causing unexpected termination or excessive thread creation.
Docker may kill a Java process that requests more memory than the container allows.
Java may over‑estimate available CPU cores, leading to too many threads in ParallelStreams or ForkJoinPool.
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().
Solution: upgrade Java (e.g., Java 10) or set JVM flags such as -Djava.util.concurrent.ForkJoinPool.common.parallelism=8 and configure heap/Metaspace sizes.
Conclusion
This article introduced Docker’s core concepts—image, container, repository—its six main advantages, common commands, and highlighted Java compatibility problems in older JDKs along with mitigation strategies.
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.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
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.
