Introduction
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).
- https://docs.docker.com/engine/reference/commandline/images/
- https://www.c-sharpcorner.com/article/docker-tutorial/
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:
- Create & Push Image to GITLAB > Packages > Container Registry
- Create & Push Image to Docker hub (create an account here: https://hub.docker.com/)
Steps
Image creation in GITLAB Registry
- Create a docker file in the parent project directory where the ".gitlab-ci.yml" file is present.
- Update the YML file to create an image with these lines.
- Push/Commit/Check-in Everything (Dockerfile + .gitlab-ci.yml)
- Check the pipeline CI/CD pipeline, it will automatically execute and create an image at the GIT Registry.
Image creation in DOCKERHUB
- Create an Account in DockerHub.
- Docker file part is already done in the above steps.
- Update the YML file to create an Image with these lines.
- Push/Commit/Check-in Everything(Dockerfile + .gitlab-ci.yml)
- 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 : "attachement.zip"
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















Join the conversation! Your thoughts help the community grow.