Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

GitLab Deploy – Container Registry – A Complete Guide

Here’s a complete step-by-step guide for:

โœ… Building a Docker image
โœ… Storing (pushing) it to GitLab’s Container Registry
โœ… Using GitLab CI/CD pipeline with GitLab SaaS 18.x


๐Ÿš€ Use Case

You want to:

  • Build a Docker image from your code
  • Push it to GitLabโ€™s Container Registry
  • Use it later for deployment or as base image

๐Ÿงฑ Prerequisites

  • A GitLab project on GitLab.com (SaaS)
  • GitLab CI/CD enabled
  • .gitlab-ci.yml file created
  • Dockerfile at the root of your project

๐Ÿ“ Step 1: Create a Dockerfile

Hereโ€™s an example Dockerfile for a Java app:

# syntax=docker/dockerfile:1
FROM openjdk:17-jdk-slim
COPY ./target/myapp.jar /app/myapp.jar
CMD ["java", "-jar", "/app/myapp.jar"]
Code language: PHP (php)

Make sure your JAR is built to ./target/myapp.jar via Maven or Gradle.


๐Ÿ“ฆ Step 2: Understand Your GitLab Container Registry URL

GitLab automatically enables a private container registry for every project:

registry.gitlab.com/<namespace>/<project>
Code language: HTML, XML (xml)

๐Ÿ“Œ Example:

registry.gitlab.com/yourusername/myapp

You can view it in:
Project โ†’ Deploy โ†’ Container Registry

  • โœ… <namespace> can be:
    • A personal username (yourusername)
    • A GitLab group (yourgroup)
    • A GitLab subgroup path (yourgroup/subgroup)
  • โœ… <project> is always the project name

โš™๏ธ Step 3: Configure .gitlab-ci.yml

Hereโ€™s a full working example:

stages:
  - build
  - dockerize
  - push

variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

# Build your app (optional if using compiled files)
build-job:
  stage: build
  image: maven:3.8.7-openjdk-17
  script:
    - mvn clean package -DskipTests

dockerize-job:
  stage: dockerize
  image: docker:latest
  services:
    - docker:dind
  before_script:
    - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
  script:
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
  only:
    - main
Code language: PHP (php)

๐Ÿง  Explanation of Important Variables

VariablePurpose
$CI_REGISTRYPoints to registry.gitlab.com
$CI_REGISTRY_IMAGEYour project-specific Docker registry path
$CI_JOB_TOKENGitLabโ€™s built-in token for authenticating CI jobs
gitlab-ci-tokenRequired user for registry auth inside CI/CD

๐Ÿ” Step 4: CI/CD Authentication

GitLab uses:

  • Username: gitlab-ci-token
  • Password: $CI_JOB_TOKEN

Docker login is done via:

echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
Code language: PHP (php)

๐Ÿ” Step 5: View Container in Registry

After pushing:

  1. Go to your GitLab project
  2. Navigate to Deploy > Container Registry
  3. You’ll see the image like: registry.gitlab.com/yourusername/myapp:abcdef1

๐Ÿ› ๏ธ Step 6: Pull and Use the Image Anywhere

From any machine (with Docker installed):

docker login registry.gitlab.com
docker pull registry.gitlab.com/yourusername/myapp:<tag>
Code language: HTML, XML (xml)

๐Ÿ” Optional: Use latest Tag and Versioning

variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
Code language: PHP (php)

Or for versioning:

IMAGE_TAG: $CI_REGISTRY_IMAGE:${CI_COMMIT_REF_NAME//\//-}
Code language: PHP (php)

โœ… Summary

StepDescription
1Write a Dockerfile
2Identify your GitLab container registry path
3Configure .gitlab-ci.yml to build & push
4Use docker login with CI_JOB_TOKEN
5View in Deploy โ†’ Container Registry

Great observation! The line:

services:
  - docker:dind
Code language: CSS (css)

is critical when using Docker inside GitLab CI/CD pipelines โ€” especially when building or pushing Docker images.


๐Ÿ” What is docker:dind?

  • **dind** stands for Docker-in-Docker.
  • docker:dind is a Docker image that runs the Docker daemon as a background service inside your CI/CD job.
  • This allows the main job container to use Docker commands (docker build, docker push, etc.), even though it’s running in an isolated environment.

๐Ÿ”ง Why is It Needed?

GitLab CI/CD runs your job steps inside a container (e.g., docker:latest), which doesn’t have the Docker daemon running by default.

So you need to add:

services:
  - docker:dind
Code language: CSS (css)

This launches a background Docker daemon, which your main container can talk to (usually via the socket on localhost or Docker host networking).


๐Ÿงช Example Use in Context

dockerize-job:
  stage: dockerize
  image: docker:latest        # Main container with Docker CLI
  services:
    - docker:dind             # Side container with Docker daemon
  script:
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
Code language: PHP (php)
  • docker:latest โ†’ contains the Docker CLI
  • docker:dind โ†’ provides the Docker daemon to execute docker commands

๐Ÿ” Important: Secure Docker-in-Docker

For security and performance:

  • GitLab runs Docker-in-Docker in privileged mode automatically when using their Docker executor.
  • You may explicitly add (if self-hosted):
  tags:
    - docker
  variables:
    DOCKER_TLS_CERTDIR: ""
Code language: JavaScript (javascript)

This disables TLS cert enforcement (GitLab-specific tweak for dind).


โš ๏ธ Alternatives to docker:dind

  • Kaniko: A rootless, safer Docker image builder (good for Kubernetes-based runners)
  • Buildah + Podman: For more secure container builds without daemon
  • GitLab CI with remote Docker host

โœ… Summary

docker:dindExplanation
Docker-in-DockerRuns Docker daemon inside CI/CD service
Required fordocker build, docker push, etc. in pipeline
Used alongsideDocker CLI image (docker:latest)
Daemon runs inBackground, accessible to main job container

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Hereโ€™s a clear and professional explanation of the three related concepts you asked about โ€” all of which are critical parts of secure software development, especially in…

Read More

Top 10 AI Code Review Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI code review tools have become essential for developers aiming to enhance code quality, streamline workflows, and accelerate software delivery. These tools leverage advanced…

Read More

Top 10 Expense Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction Expense management tools are critical for businesses of all sizes in 2026 as they help streamline financial processes, improve budgeting, ensure compliance, and enhance financial visibility….

Read More

Top 10 Web Application Firewall (WAF) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In the rapidly evolving landscape of cybersecurity, Web Application Firewalls (WAFs) have become a critical component in defending web applications from malicious attacks such as SQL…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x