In modern software delivery, containerization has become the de-facto standard for packaging and deploying applications. While Docker Hub is widely used, many organizations rely on private registries (Harbor, Nexus, Artifactory, AWS ECR, Azure ACR, Google GCR, etc.) to securely host and distribute container images.
This blog walks you step-by-step through the process of creating a project locally, building a Docker image, and pushing it directly to a private Docker repository.
π οΈ Prerequisites
Before you begin, ensure you have:
- Docker installed on your local machine.
- Access to a private registry (credentials + URL).
- A project to containerize (weβll use a Java Spring Boot example here).
π Step 1: Create Your Project
Letβs assume you have a Spring Boot application. Build it locally:
mvn clean package -DskipTests
This will generate an executable JAR inside the target/
folder.
π Step 2: Write a Dockerfile
Your Dockerfile defines how the container image will be built.
Example:
FROM eclipse-temurin:17-jdk-alpine
WORKDIR /app
COPY target/myapp.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
Hereβs whatβs happening:
- Base image: Uses a lightweight JDK 17 image.
-
Workdir: Sets
/app
as the working directory. - Copy: Copies your JAR into the container.
- Entrypoint: Defines the startup command.
π Step 3: Build the Docker Image
Run the following in the project root directory:
docker build -t myapp:1.0 .
This builds an image named myapp
with the tag 1.0
.
π Step 4: Tag the Image for Your Private Registry
You need to reference your private registry when tagging the image.
For example, if your registry is hosted at myregistry.example.com:5000
:
docker tag myapp:1.0 myregistry.example.com:5000/myteam/myapp:1.0
Now the image is ready to be pushed.
π Step 5: Authenticate with the Registry
Login using Docker CLI:
docker login myregistry.example.com:5000
You will be prompted for a username and password (or token).
π Step 6: Push the Image
Push the tagged image to the registry:
docker push myregistry.example.com:5000/myteam/myapp:1.0
Once uploaded, your team can pull and use this image anywhere.
π Step 7: Verify the Push
Confirm the image is available in the registry:
docker pull myregistry.example.com:5000/myteam/myapp:1.0
If successful, your private registry is now serving your custom image π.
β‘ Pro Tips
-
Versioning: Always use semantic version tags (
1.0.0
,1.1.0
) for production images. Avoid relying only onlatest
. - Automation: Integrate this workflow into CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins).
-
Security: Configure
imagePullSecrets
in Kubernetes to authenticate private registries. - Efficiency: Use multi-stage Docker builds to reduce image size.
β Conclusion
Youβve successfully:
- Built a project locally.
- Containerized it with a Dockerfile.
- Tagged and pushed the image into a private repository.
This workflow forms the backbone of modern DevOps practices, enabling teams to ship applications faster and more securely.
Top comments (0)