Creating Image Using YML File in GITLAB


In this blog, we discuss creating/converting an image into an application and pushing it to the Docker Hub and GITLAB Registry.  This is a continuation of part 1.
Here we will convert an application created in part I into an image (refer below).
Here we will be creating an image using the GitLab YML script file as a part of the pipeline into various steps.
We will be creating an image in 2 ways:
  1. Create & Push Image to GITLAB > Packages > Container Registry
  2. Create & Push Image to Docker hub (create an account here:
Image creation in GITLAB Registry
  1. Create a docker file in the parent project directory where the ".gitlab-ci.yml" file is present.
  2. Update the YML file to create an image with these lines.
  3. Push/Commit/Check-in Everything (Dockerfile + .gitlab-ci.yml)
  4. Check the pipeline CI/CD pipeline, it will automatically execute and create an image at the GIT Registry.
Image creation in DOCKERHUB
  1. Create an Account in DockerHub.
  2. Docker file part is already done in the above steps.
  3. Update the YML file to create an Image with these lines.
  4. Push/Commit/Check-in Everything(Dockerfile + .gitlab-ci.yml)
  5. Check For pipeline CI/CD pipeline will automatically Executes and Image is created at DockerHub.
**You can also download updated gitlab-ci.yml file and new DockerFile just added now. There is no change in project, it’s just a HelloWorld web application in .NET Core. Its just a DEVops related file changed to YML docker, so it will be handy to check files.
**Refer : "" 
GitLab Registry
Step 1
You can create a Docker file directly in GitLab using a template or at your local using visual studio. Using a template (dotnet, python, Go language related running image) will be easier, as it gives you a predefined set of instructions to normally execute a valid docker file.
Our application is in Dotnet core so template file I am attaching in *.zip for reference you can download it and use it. Just remember Dockerfile is without any extension.
Step 2
Once Dockerfile is created with a set of lines, we can now add scripts in the YML file to create an image and push it to the Gitlab registry.
Step 3
Push the changes to GitLab. Only 2 files are changed here.
Step 4
Once pipeline runs successfully, you can check created image at this path.
Packages > Container Registry
After 2-3 minutes, when the job executes successfully, it will look like this. Now we are done creating our first image using a yml file.
Docker Hub
Step 1
This is to create an account and that’s it. (In future steps we will be using docker id/password to connect to Docker Hub and push image here)
The first landing page will be like this:
You can create an empty repository like this. (In future steps it will be needed again to push an image).
Some set of commands is also given for how a tag is done for a Docker image (syntaxes basically we will be using the inside of our yml file)
You can explore inside Empty repository what we created. It will show tags (representation of images because image are also neither file nor have any extension)
Step 2
Docker file we have already created. So skip this step.
Step 3
Updated .gitlab-ci.yml file attached for quick reference.
Step 4
Push the changes to GitLab. Only the Dockerfile has changed.
Step 5
The pipeline should run automatically. Once the pipeline runs successfully, you can check the created image in DockerHub.
  • Refresh the Docker Page. you will see inside TAG tab images just uploaded to Docker hub using our Pipeline. You can cross verify the same Committed ID was the last ID in GIT.
  • You can also check console of GITLAB pipeline how yml script was executed here
So we are done with 2 types of image creation in separate Repository (gitlab/Dockhub).
The last work is to deploy these images to the server. You can do using AWS, GoogleCloud, Kubernetes, OR Azure.
Inside GitLab > Left Panel > Menu > Operations > Kubernetes.