How to Build, Deploy, and Manage Docker Images with a Private Registry
This guide explains the advantages of containerized deployment, walks through creating a Dockerfile, building and tagging images, setting up a private Docker Registry with a web UI, configuring clients, and using Docker Compose to launch containers, providing a complete end‑to‑end workflow for Java services.
Benefits of Containerized Deployment
Docker, as a lightweight virtualization method, utilizes system resources efficiently without the overhead of full hardware virtualization or a complete operating system, enabling second‑level or even millisecond‑level startup times and guaranteeing consistent runtime environments across all stages.
Building the Image
Dockerfile
Place a Dockerfile in the docker directory of the my-project-server module to define a custom image that follows the "build once, run anywhere" principle.
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 8899 FROM: specifies the base image (openjdk:8-jre). MAINTAINER: project maintainer. RUN: creates the /app directory. COPY: copies the built JAR into the image as app.jar. ENTRYPOINT: defines the container start command and parameters. EXPOSE: declares the service port (8899).
Start Building
Create a working directory on the host and copy the JAR and Dockerfile into it. mkdir -p /usr/local/docker/my-project/docker Build the image: docker build -t my-project-server:v1 . Verify the image:
$ 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 Registry
Docker Registry
Create the registry directory and a docker-compose.yml file:
mkdir -p /usr/local/docker/registry
cd /usr/local/docker/registry
version: '3.1'
services:
registry:
image: registry
restart: always
container_name: registry
ports:
- 5000:5000
volumes:
- ./data:/var/lib/registryStart the registry container:
docker-compose up -dDocker Registry Web UI
Create a frontend directory and its docker-compose.yml:
mkdir -p /usr/local/docker/docker-registry-frontend
cd /usr/local/docker/docker-registry-frontend
version: '3.1'
services:
frontend:
image: konradkleine/docker-registry-frontend:v2
ports:
- 8080:80
volumes:
- ./certs/frontend.crt:/etc/apache2/server.crt:ro
- ./certs/frontend.key:/etc/apache2/server.key:ro
environment:
- ENV_DOCKER_REGISTRY_HOST=192.168.110.158
- ENV_DOCKER_REGISTRY_PORT=5000Access the UI at http://192.168.110.158:8080/ to view uploaded images.
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 dockerUploading the Image
Tag the image for the private registry and push it:
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 via the registry API:
$ curl 192.168.110.158:5000/v2/_catalog
{"repositories":["my-project-server"]}Running the Container
Define a docker-compose.yml for the application:
mkdir -p /usr/local/docker/my-project
cd /usr/local/docker/my-project
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/ShanghaiStart the service and check its status:
docker-compose up -d
docker ps -aTest the API endpoint (e.g., http://ip:8899/sys-user/get/all) to confirm the container is running correctly.
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.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
