How to push Docker Image to GitLab Registry|Push Dockerized Node.js App to GitLab Container Registry

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so in this session we are going to learn how to push Docker image to bitlab registry so as you can see this is my gitlab account and now we are going to learn how to push Docker image to gitlab registry so first of all so let's go to the official page so here you can see in gitlab official page you can see build and push image so here we are going to build and push Docker image right so there are two ways to push Docker image to uh sorry Docker image push to gitlab registry there is two types first install Docker on your instance that means your gitlab Runner uh then second is here you can see you can use this Docker commands in your dot EML file you can see so first of all as you can see here you you need to configure your dot gitlabs dot ci.yaml file here you need to add these lines right to build this image then service then step you can see build Docker build hyphen T my Docker image that means here if you want to build Docker image there is two ways first you can install Docker on your gitlab Runner and the next is you can use this code in your dot gitlab ci.aml file you can see that your image name should look similar to this you can see image name and so on then Services then stage and in script build your Docker image and then you can see the image name and so on here okay here you can see your yaml file first of all your image then stage build then you can see then script Docker login then CR registry then Docker build then Docker push right that means if you want to if you don't want to install Docker on your gitlab Runner then you can use this second option that means you can use this code on your dot uh dot gitlab.co.aml file to build and push Docker image right but here in this session we are going to learn how to build and push Docker image so here I am going to install Docker on my gitlab Runner right so we are going to choose first option so let's install so first of all as you can see here in my command one as you can see here I have already installed sorry install gitlab Runner if I go to my home page you can see gitlab Runner right if you don't want uh sorry if you don't know how to install gitlab Runner then you can use my article so you can follow this article here you can see how to install gitlab runner on Ubuntu so you can follow this so here I have already installed Docker sorry gitlab Runner now let's register our gitlab runner so how to register so first of all you need a gitlab registry so here as you can see I have already created one registry with the name push Docker image to gitlab registry to push this Docker image so here first of all you need a registry so as you can see in my registry as of now I have only one file right Runner let's understand this image first to push gitlab to push this image to gitlab Runner so let's understand first so as you can see here first of all gitlab so then here you can see okay wait here first of all we are going to push and commit our code in gitlab then check out in CI CD right then check out with cicd then it will push this code into our gitlab container registry right then as you can see in Docker the docker uh the docker board push to get a CI CD then it will push to gitlab registry so that's the overall that we are going to learn okay so now let's start so first of all you need a registry gitlab registry so as you can see here my registry so now let's register our gitlab runner so how to register so first of all go to the settings as you can see in left side settings then go to the CI CD then let's scroll down and as you can see here so it Runners right click on expand so here you can see this Runner are assigned to this project that means as of now we don't have any Runner right so click on new project Runner then choose your operating system Linux and then tag so I'm going to enter look and it's optional it's also optional so then click on creator so as you can see Runner created so now you can see the command to register your git lab Runner so I'm going to copy the command and paste in my terminal to register map so as you can see enter the gitlab instance URL so here is your url then it will ask about our token so let's enter our token then enter name for the runner so my Runner will be shell okay so can I see the message run a registered successfully okay so let's go to the runner and let's wait for a few seconds so now as you can see the message you are created a new Runner right so go to the runner page that means we have successfully created our runner so let's check so let's expand our Runners and let's check our runner thank you so as you can see our learner you can see it's running assign project Runner and it's running running is online okay so let's inside the runner click on edit and I'm going to run the entire job as well as log to current project and click on Save changes okay so it's done right so we have successfully created our learner and we have successfully updated our runner now now let's push code into our registry so here I'm going to use node.js project that means package.json file Docker file as well as server.js file so let's push this code into our repository right so first of all we need to clone our repository so here as you can see I already cloned my repository you can see my repository folder in C drive my folder name is push Docker image to gitlab registry right and as of now I have only one file with the name redmi.amd5 so here I am going to use node.js project right so here I have to close it you can see I have some files so I'm going to use this so if you don't have then you can clone my repositories and you can use this process okay now we have package.json file Docker file as well as server.js file so let's push this code into a repository and let's understand the code so let's push this code first so here I'm going to use this good pad git bash to push this code into a repository so first of all let's insert our repository so my repository name is push token image to gitlab registry then I will put our commit so my comment will be device added push okay it's done so let's check so go to the code and click on depository so as you can see our file one minute ago Docker file package.json file as well as server.js file right okay so let's understand one by one so first of all let's understand package.json file foreign [Music] [Music] server.js file so here in server.js file as you can see our Port is adity and the host is 0.0.0.0 that means any IP address right okay so that's all server.js file so that's our node.js project here you can see package.ts and file Docker file as well as server.js file okay so now the next is here we need to add some variables here so first of all before adding variables we need a or tokens right so here first of all how to create tokens so first of all go to the settings and go to the Repository then let's scroll down and as you can see deploy tokens deploy tokens allow access to package your repository and registry image so click on expand and here we need to create token so enter a name so my token name will be image and it's optional it's also optional so I'm going to choose this all then click on create deploy token so as you can see here in gitlab official report official site you can see deploy token so how to deploy token you can see first of all Colonial git repository then pull from push gitlab container registry okay here you can see username so username in the HTTP authentication framework the default username format is like this and you can specify a custom username when you create the deploy token then token is password in the HTTP authentication framework right so you can see project deploy token as well as group deploy token so project the protocol permission apply only for the project and group deploy token is permission applied with all projects so here we are going to create this project deployment so that means it will permission apply only for this project so as you can see our token is created you can see so use this token as a password save it the password it cannot be recovered so that's why I'm going to copy my token name in my notepad as well as my token that's my token name and here's my token okay because you can see use this token as a password and save it this password cannot be recovered so that's why I'm going to stay here okay so now go to the variables so we need to add some variables so go to the settings and then cicd then let's scroll down as you can see variables so you can see variable store information like password and secret keys and that you can use in your job script and each project can define a maximum 8000 variables right okay so now here we are going to add some few variables so let's click on expand and click on ADD variables so the first variable is as you can see here's the first variable is we need to add this CA deploy user that means our username so I'm going to add my variable here see I deploy user that means that username that we have created our token that means our Docker username copy my coupon username and paste in value section and I'm going to remove this protect variable flag and click on ADD variable the next variable is CI deploy password that means CID password means our token that we have just created here protect variable flag and Records add variable now the next is here as you can see CR registry so how to find CR registry so here as you can see in gitlab official page so as you can see in gitlab official page authentically the container registry right so you can see here talk indicate with container registry you can use a personal access token deploy token project access token and group access token right so here we need to find our CR register right how to add our variable in CR registry so here in your settings sorry here in your left side as you can see deploy so let's scroll up click on deploy and as you can see container registry so let's click on container registry and let's find our CI registry so you can see in your container registry there are there are no container Image store as of now now you can see if you are not ready to login and so on you can see here you can add an image to this registry with the following commands right so our current CR registry is here you can see our CR registry from here to here registry dot gitlab.com registry name right so that's our CI registry variable so I'm going to copy and go to the CI CD and then add our variable so that's the way to find our CR registry variable right if you don't know your CR registry then you can go to The Container registry and then you can find your CR registry sorry so let's go to the variables and click on expand and let's add new variable okay and the next variable name is CR registry foreign password that means our token password sorry token then see I deploy user that means our token username that's CI registry that means our registry how to find go to the containers firstly go to the deploy then container registry and then you can foreign so let's go to the build sorry let's go to the port and go to the Repository now here is my GitHub share.aml file I'm going to copy this and let's understand so first of all I'm going to copy this foreign so click on new file so our file name is dot gitlab.ci.dml file and you have to paste my file okay so first of all let's understand our code so you can see firstly default before script Docker information then stage the two stage here build and push then build Docker image your stage Docker build and script is Docker login hyphen you see I deploy user that means token username then CID plug password that means our token that we have added in our variables and this here register that means our registry URL registry that means we are going to build this into our gitlab Repository then next is push to registry so Docker push then you can see the script Docker login hyphen use here deploy user then FNP CID plug password then see a registry then Docker push into our ditlab registry URL right that means CR registry gitlab repository URL that we have added in our variable right okay now let's commit and let's see our pipeline so let's go to the build and let's go to the pipeline so our pipeline will fail let's check you can see stay why because we don't have Docker let's check the error foreign Docker command not found why because we don't have blockers so as I told you here we have two types to push Docker image to our gitlab registry first of all installed Docker on our gitlab runner and then next is use this code here you can see that code into our gitlab uh sorry dot gitlab.com right so here we have we have choose the first option installed Docker so let's install Docker on all git library history so here is our registry so if I click your Docker images you can see we don't have any rocker right so let's install Docker using this command okay it's done then we need to give some permissions to our Dockers which permissions so here first of all these user mode this this CH note triple six permission okay now it's done now let's rerun our job so here is the retry so as you can see our job is running you can see the status is running so let's check so as you can see our first job is succeed right that means Docker build so we have successfully build our Docker image now let's check our second job Docker push so as you can see it's running so as you can see our second job is running Docker push so let's check so it takes few seconds wait for few seconds foreign so here in this session we have learned how to push Docker image to our gitlab registry using docker that means using Docker install in our gitlab runner right so thank you for watching
Info
Channel: DevOps Hint
Views: 2,902
Rating: undefined out of 5
Keywords: How to push Docker Image to GitLab Registry, Push Dockerized Node.js App to GitLab Container Registry, push docker image to gitlab container registry, gitlab ci cd tutorial, gitlab ci cd, gitlab ci cd docker, gitlab ci, continuous deployment, continuous integration, gitlab runner, gitlab container registry tutorial, gitlab container registry, docker tutorial
Id: lsrKKA7rF_I
Channel Id: undefined
Length: 34min 12sec (2052 seconds)
Published: Fri Aug 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.