Docker Container Deployment: Building Images, Setting Up a Private Registry, and Running Services
This guide explains the advantages of Docker containerization, shows how to write a Dockerfile and build a custom image, details the creation of a private Docker Registry with Docker‑Compose and a Web UI, and demonstrates tagging, pushing, pulling, and running the image in production.
Benefits of containerized deployment – Docker uses lightweight OS‑level virtualization, eliminating the overhead of full VMs, enabling second‑level startup times and guaranteeing identical runtime environments across development, testing, and production.
Building the image
Create a Dockerfile in the my-project-server module:
FROM openjdk:8-jre
MAINTAINER Micromaple <[email protected]>
RUN mkdir /app
COPY my-project-server-1.0.0-SNAPSHOT.jar /app/app.jar
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar", "--spring.profiles.active=prod,druid-prod"]
EXPOSE 8899The Dockerfile directives are: FROM: base image (openjdk:8-jre). MAINTAINER: author. RUN: create /app directory. COPY: copy the built JAR into the container. ENTRYPOINT: command to start the Java application. EXPOSE: expose port 8899.
Build the image: docker build -t my-project-server:v1 . Verify the image exists:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
my-project-server v1 ed30386b06d2 11 seconds ago 334MB
openjdk 8-jre 26ac3f63d29f 9 months ago 273MBSetting up a private Docker Registry
Create a directory and a docker-compose.yml for the registry:
version: '3.1'
services:
registry:
image: registry
restart: always
container_name: registry
ports:
- 5000:5000
volumes:
- ./data:/var/lib/registryStart it with: docker-compose up -d Optionally deploy a Web UI (e.g., konradkleine/docker-registry-frontend) with its own docker-compose.yml and configure ENV_DOCKER_REGISTRY_HOST to point to your registry IP.
Client configuration
Edit /etc/docker/daemon.json to trust the private registry:
{
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.110.158:5000"]
}Reload and restart Docker:
systemctl daemon-reload
systemctl restart dockerTagging and pushing the image
docker tag my-project-server:v1 192.168.110.158:5000/my-project-server:v1
docker push 192.168.110.158:5000/my-project-serverVerify the upload with:
$ curl 192.168.110.158:5000/v2/_catalog
{"repositories":["my-project-server"]}Pulling and running the image
Remove the local copy, then pull from the private registry:
docker rmi my-project-server:v1 192.168.110.158:5000/my-project-server:v1
docker pull 192.168.110.158:5000/my-project-server:v1Start the container with Docker Compose:
version: '3.1'
services:
my_project_server:
image: 192.168.110.158:5000/my-project-server:v1
container_name: my-project-server
restart: always
ports:
- 8899:8899
volumes:
- ./logs:/logs
environment:
TZ: Asia/Shanghai docker-compose up -dCheck the container status with docker ps -a and access the service at http://<em>ip</em>:8899/sys-user/get/all.
Overall, the article provides a step‑by‑step workflow for containerizing a Java service, creating a private Docker Registry, and deploying the service consistently across environments.
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.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.
