Cloud Native 9 min read

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.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Docker Container Deployment: Building Images, Setting Up a Private Registry, and Running Services

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
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

The 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     273MB

Setting 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/registry

Start 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 docker

Tagging 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-server

Verify 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:v1

Start 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 -d

Check the container status with docker ps -a and access the service at http:// ip :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.

dockerDevOpscontainerizationDocker-Composeprivate-registryimage-build
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

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.