#!/bin/bash
CRED="<your-rw-deploy-token-for-the-gitlab-project>"
# Change these for the target image / group.
DOCKERHUB_IMAGE="openjdk:11-jre-slim"
GITLAB_REGISTRY="registry.gitlab.com/your/project/path"
# Calculate the GitLab image name.
GITLAB_IMAGE="$GITLAB_REGISTRY/$DOCKERHUB_IMAGE"
# Pull the image from DockerHub
docker pull $DOCKERHUB_IMAGE
# Tag the image with the GitLab Container Registry path.
docker tag $DOCKERHUB_IMAGE $GITLAB_IMAGE
# Push the image to the GitLab Container Registry.
docker login registry.gitlab.com -u unused -p $CRED
docker push $GITLAB_IMAGE
You can generate deploy tokens (R/W) in your project settings. Group level tokens will let this operate across multiple projects in a group.