How to Push a Docker Image to Docker Hub Using Jenkins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to talk about how to push a docker image to docker hub using jenkins [Music] are you new here if you are welcome and if you are new here you don't know who i am my name is darren pope and i'm a developer advocate for cloudbees so what happens when you build a docker image well depending on where you're building it if it's on your laptop if it's on a different server that image just lives within that machine what we want to do is be able to produce a docker image that can be and will be pushed up to docker hub so not only that we can consume it but potentially other people all around the world can use it let's talk about what versions of jenkins that we're using today we're using jenkins 2.27.2 when it was installed it was installed with install suggested plugins and we also have an agent connected to that jenkins controller to get started we're going to need to set up credentials to be able to authenticate from our jenkins controller to docker hub you could use your own password for your docker hub credentials but it's probably better to create an access token that way you're not using your password as a credential to set up the access token inside of docker hub log into your docker hub account and then go up to your name and then click on account settings once you've done that you'll click on security and right here you'll see access tokens so i'm going to create a new access token i'm going to give it the name of jenkins and click on create and then what we're going to do is we are going to copy this token so i'm going to save that so i can use it in the next step now that i've copied that access token over off to the side let's go over to our controller and set up the credentials so what we want to do is set up a username and password credential type so we'll go to manage jenkins manage passwords click on jenkins global credentials and click on add credentials so we're going to use a username with password my username is darrenpope and the password is going to be the value of the access token so i'll paste that in in fact i'm going to paste it in here make sure i have the right one i do that's great and now i need to set up an id because we're going to be using this id within our jenkins pipeline to be able to interact with docker hub so my id is going to be darrenpope dockerhub and the description is also darrenpope-dockerhub so let's go ahead and save this now that we have our credentials set up let's go and create a job so we'll go over to dashboard we'll click on create a job we're going to name the item docker hub dash example and we're going to create a multi-branch pipeline of this i already have an example repository that has both a docker file and a jeans file in it so that's what we're going to use so i'm going to add a source we're going to use get let me grab my link for my repository and this is a public repository on github if you want to take a look at it you can see it at darrenpope dockerhub dash example let's go ahead and click on save now if you were to go and take a look at this repository you'll notice that there is nothing on the main branch sort of on purpose i have nothing there but i do have a jenkins file in the zero one no plugins necessary branch so let's go take a look at this job as it's running and we can see here that the job ran successfully if we take a look at this we have our login for docker login we pushed our image up to the up to docker hub and then we did a log out well let's take a look at what our pipeline is actually doing before we do that let's take a look at dockerfile all this is is just a from alpine and whatever the version is in this case this happens to be the latest version as of today but if we take a look at our jenkins file what we have is an environment set up accessing our docker hub credentials that we define darin pope docker hub we're loading that into an environment variable first step is we do a docker build i give it a tag of darren pope slash dp alpine latest then we log in to docker hub and i'm using the password standard in you'll notice when we take a look back at our log that it's just giving us a warning that hey your password is going to be stored unencrypted in the home directory where this is running docker config json this is up to you you have to make the decision is this okay or not if it's not docker has some explanations of how to use credential helpers to help manage that so it is not setting out in clear text that's out of scope for today but i wanted you to be able to see this and understand i might need to go ahead and take advantage of those credential helpers once we get logged in we just do a simple docker push and then finally we do a docker log out now notice how we're doing the docker log out i'm doing a docker log out on the post always for the whole pipeline i want to make sure that no matter what happens i always want to log out no matter what the scenario is now let's go over to docker hub and see what happened if we go back and take a look at docker hub let me go ahead and close this up here and we go back up to my account so i'll click on docker hub that will take me to my logged in information now we can see had to refresh it we now we can see the dp alpine was updated three minutes ago and if we take a look at it we can see here that it was pushed three minutes ago and pulled three minutes ago and it's all ready to go and that's it pretty short pretty simple we didn't have to but we did set up an access token inside of docker hub so we could use that as the password for our credentials that we're setting up inside of our jenkins controller we already had a repository set up with a jenkins file that did a docker build docker login docker push and a docker logout and our dockerfile was really simple just from alpine so it was a very small image to push up to docker hub there are numerous ways that you can push images to docker hub this is one of the ways that you can do it with jenkins if you have any questions or comments you can reach out to us on twitter at cloudbeesdevs if this video was helpful to you give us a thumbs up and if you haven't subscribed to cloudbees tv yet why not take a moment click on that subscribe button and then ring that bell and you'll be notified anytime there is new content available on cloudbees tv thanks for watching and we will see you in the next video you
Info
Channel: CloudBeesTV
Views: 19,831
Rating: undefined out of 5
Keywords: darin pope, jenkins, jenkins tutorial, jenkins docker, jenkins docker hub, docker hub, jenkins pipeline, docker images, docker build, docker image, docker push, docker hub tutorial
Id: alQQ84M4CYU
Channel Id: undefined
Length: 7min 47sec (467 seconds)
Published: Tue Apr 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.