Duration 21:54
16+
Play
Video

How to Build and Test Your Docker Images in the Cloud

Peter McKee
Developer Relations Manager at Docker
  • Video
  • Table of contents
  • Video
DockerCon 2020
June 15, 2020, Online, Austin, TX, USA
DockerCon 2020
Request Q&A
Video
How to Build and Test Your Docker Images in the Cloud
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free
Add to favorites
5.49 K
I like 0
I dislike 0
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free
  • Description
  • Transcript
  • Discussion

About speaker

Peter McKee
Developer Relations Manager at Docker

Solid experience leading and managing teams to develop highly reliable enterprise software systems. Excellent troubleshooting and problem solving skills. Motivated by challenging and impossible to solve problems. Self-motivated in continuing education. Possesses the skills to build, strengthen, and maintain people relationships.

View the profile

About the talk

--

Companies today want to build and ship features faster to help gain a competitive edge and keep pace with the ever changing landscape of their businesses. But moving your code to the cloud and running it in containers is not a simple task. Docker Hub is an essential part of automating your build pipeline and beforming continuous testing. In this talk, we'll take a look at what exactly Continuous Integration looks like and how to setup a CI pipeline using Docker Hub's AutoBuilds and AutoTests.

Speaker: Peter McKee, Docker

Twitter: @pmckee

Share

Hello everybody. Welcome to my talk. My name is Peter MacKay. I'm on the developer relations team here at dr. And telling them talking about how to build and test your doctor images in the cloud. So it's like look the agenda. So we'll start things off by talking about continuous integration. What? Exactly is continuous integration and then we'll take a look at Docker Hub in the way it does see, I will start out by integrating get into Hub and then we'll take a look at setting up. Simple. Auto built-in auto test And I'ma go a little deeper into that and will do more advanced custom builds

and custom test running. And then after that, we'll finish up by taking a look how Docker Hub can fire off webhooks, once your images, it pushed into a rebuilt, and that way, you can integrate with third-party products So what exactly is continuous integration? So continuous integration is where developers merge their changes into a common core repository whenever features completed or changes made once these changes and burst, the CI system can then run automated Bill to test the verify the changes. This is often done multiple times throughout the day. The

way it's kind of works is the developers working locally on their machine. They create a free tree branch to either add a feature or fix a defect and then once they're done and run their tests local then they push up to a remote Branch usually kind of PR and then once that PR is signed off on that gets merged into a master branch. And then Docker Hub is listening to that to the merges into Master branch in a Web book is fired and sent to HUB. Listen to that webhook. And then it will then check out that Branch. It will find your dockerfile, he will run your build.

Build your image once that is past. Then it'll run your tests if you have them set up once, all your tests have passed and it'll push your image into the repo. Sucks. Flow is what we're going to be looking at today. Okay, so we can spend a lot of time and hub, if you don't have a sub account, please go sign up, it's free. So the first thing we're going to be looking at is how to set up get home. So, let's go into Hub. So I come over here and the browser and go to hub.aa.com. Then I'ma click sign in. If you don't have an account and go ahead and create one,

doctor ideas and account is free. So let me sign in at my doctor ID, in my password, once I'm signed in and go to this menu in the top-right, drop this down and then go to account settings, over here to link accounts. We have to source code repositories that we can connect to get help and bitbucket. We're going to connecting to get Hub. Some The Click connect. It's requesting that I sign in so and her my username and password sign in I'm probably get a 2fa here. Yep. And so

285-622-8056 20 All right. Now, I can turn off my messages. okay, so now we're back here and home And I just connected get help in there but now we want to create a repository. So go to repositories and we could see. I have Pima key and these are the repositories I have in my current organization. I need my personal name. Someone to create a repository. I go in there I'm going to call. Hello world. And not going to put a description in there. I'm going to leave it public. And then we can either connect here or we can do it later, but let's connect now.

So I'm going to click that button. I'm going to drop down the organization. My GitHub is in Ronan. JSM, select the docker. Hello world. Okay, so let's go ahead and create that. So now I have a repository image repository set up in help and if we take a look, I don't have any images yet. I haven't pushed in the images showing the general. So let's go ahead and do that now. Let's push an image. So let's go back to, let's first. Take a look at the application real quick. So my little doctor hello world is a very simple nodejs

application. Here's the source, I have a server. It's going to be listening on port. 8080, I have a couple actually at 1 route in here. It's just listening to the route and it will return back. Hello, dockercon. Underneath the utility rectory. I have a little helper function here that'll add two numbers together and return the sum, and then I have a little test that will test that. Okay? So let's go down here to take a look at our doctor file real quick. So I have very basic dockerfile here. I'm just using notice a base image. I setup my working directory, I configure an environment

variable name port, and set it to 80, copy the package, Json into the image, I run npm install and take the source code copy that in the code. And then I tell it the command and wanted the Dock of the run is note in. Passing server Js. So, let's go ahead and filled our image, something to call the docker building to get a tag. No tagging need to give. It is the same repo that I just set up. Hello world. And I'm going to give it to the current directory that were in. And

so if you see here, we named my Repose pee McKee. Hello world night, Sophia McKee. Hello world. I had dinner. And then we go images built. So if I do a Docker images, we can see that it's built. So now we want to do is let's push this image up into hub. So I'm going to do a lock doctor, login. Docker push and I'm just going to go pee McKee helloworld and then we go, it's going to push it up into tub. Hopefully, my internet is be nice and fast today. And

wait for it. Pushed and done. Okay. So if we come back in here in the hub, Let me refresh. So we can see you guys down here. We have latest just pushed a few seconds ago, and then if we go into tags you can see that latest has been pushed. Okay. That's great. So, let's take a look at our bill does not look on builds, and then we'll come over here to the configure automated bills. Click on that number to come down here to the bottom. So you can sit. Well, actually, at the top here, you can see

the source of Pride repositories running JS. Docker - hello dash world. The location we're going to use Dockers infrastructure would keep autotest off for now. I'll talk about this in a minute but these aren't very important right now. And then we're to keep repository links turned off. And then what we need to set up as a build rule, so come over here and we'll sit will click on the build Rule and you see we have a couple options here so we can listen to this either. A branch or tags are going to listen to the branch. I'm going to listen to the master branch. And then after images built,

we're going to tag it as latest. And then we're going to, let me tell the, The Hub build system where to find a doctor found a built. So the bill contacts is where doctor will use to what context it will build in. So we give it to Route because that's a route and the name of our talk about his doctor about it. We'll keep on auto bills and do cashing took their ego and now let's go ahead and save that sounds go over to our source code. Let's make a change. So will come over here into our route and let's change this from dr. Khan to hello world summer. Save that come into my

terminal and we can see you have a change there by the yellow. So I'm going to commit that change so changes. And then I'm going to go ahead and push this up to the rebuilt. Now, before you would have to do, if you made some changes, you might run your Docker image, local, another doctor build and then push that image up. So now this happens right now, work flow. So we're going to push, push our changes up to the repository and then we're going to watch our build kickoff. So it's go ahead and push that out there.

Let's go back into Hub, let's go back into our builds. And now we can see that we have a build running right here. Are billed as finished to nce recent bills. Go to master it was successful down here at the bottom. You a build logs or doc file. And you read me, let's go and take a look at the at the laws, we can come down here and we can see the latest Shah has been pushed. So awesome happened about fifteen minutes ago. Let's see. Let's go back. So what you want to do now so we

made a change door code and then we didn't build our image locally. All we had to do is do a get push and we pushed our changes up and Doctor pick that up and build our image for us. So cool. So let's add and test. Now. So the way you add into test into into your CI pipeline in Hub is Ukraine is Docker compose. Test. Yml for you, you have to have services and you have to have set so system under test and what it stands for. And then in here you can do anything you like to do a custom build. So all we're

doing is setting the context and then telling it what? Doctors how to use. I'm using this talk about - test which is here which is a little bit richer dockerfile and we were using before I just want to be able to show the difference that you can use different doctor files, but it's basically the same. I wish I have no environmental variables. I said that the test, so this is a build argument. So you can pass into arguments to do builds with Docker, we set up a build argument Wii, Wii, default it to test them, we said a note environment pretty much the same. We also allow this to be able

to override the port argument with another bill document and then copy and our package Chase on a lock and p.m. stall, same thing. And so then, let's go back to our test sample here. And then when you get so you can give it a command to be right, we say a.m. p.m. run tests, right? So you're not familiar with no tune in p.m. in our package Json, you can set up scripts. So we have a script in here and it's just just as our test Runner and so just, we'll just we'll run and we'll run our test. So let's make another change. Let's go exchange his

back to Dunkirk on. So me, say that. And I'll come over here and now real quick. So over and hub, we don't need to do anything on our bills. The only only thing you need to do the setup auto auto test is to create that test. Damn, about you just need to create this dr. Campos. Test damn. Oh, okay. So I'm going to do a commitment. So get come in and I'm going to say changes. Okay, so let's push this up. Can we push that? And then we'll come back here in a bit, so maybe fresh real quick. And we should see we have another bill kicking off

its or build was successful. So let's take a look at the logs here. This up a little bit more down to the logs. And we can see here that our image was built. This is our test image. You can see the underscore set and then write down here. You can see Jess was run and our tests ran And they all passed. And so since I passed, you can see here that our image was pushed Pretty cool. So So we set up some simple built, and we push to push through our get repo, and we ran our bills, and then we set up

custom task. So we created a Docker compose - test Style. And so right in here. So we set up our test file. We told it what doctor father use what command we wanted to run to run our test. So that's basically how you set up some basic tests. It will run your Docker file and it also It'll also then run whatever command you want to give it to run tests. So what I want to look now is building some kind of tie into the CI process so this is where the real power of hug comes in. So there's some life cycle methods that happen

when your images are being built in, your tests are being run and we can hook into those and we call those folks. So, if you create a books folder in your repo and then if you add these files into it, these files are good run during the life cycles. and you can override the build command, you can override the pre-build and the post build, and then you could also ride override the protest, the post test, and then, you could also override Free push and push push. And so what we're going to look at is we going to set up a custom build

and so let me let me pull up that file so that I can copy your style over here real quick and so this are custom-built oh let me select all this and happiness and so basically you're Your Hooks or just bash house. She'll Scripts. And you could you have access to all these custom environment variables, the doctor will pass, and we'll set up an environment and run your bath script. So we have access to the stalker tag, you can pass and also you can and then you have a Docker file and then image name. But you can also set environment

variables and hub, custom varmint Parables. So let's go take a look at that real quick. So let's go back. Look at bills in this configure a custom environment variable, some a scroll down here. I'm sorry I'm going to configure builds and I'll come down. So I'm going to click on a custom environment durable. Imma set the port. And I want that poor to be 80. 80. So if you remember in our dockerfile We set up an environment variable and we called it Port 80. So we can add an arc here when call it port.

And we can set this to default it to 80. And then down here in Port, we want to set this to Port. Okay, let's say that and I'll show you if you remember in an AR test, you'll see the same thing here. Okay, so the argument Port equals 80 environment variable port and it sets it to build argument, okay? So that's what we did here. So, save that over here in our custom-build. Now we can take a look at doctor says, so this triggering this build, and here's a dark or tag that was triggering this built. So if it's equal, the latest,

then we're going to Echo out and say building in which report And whatever court is in that environment variable, then we're going to do a doctor bill. We're going to give it a custom Docker, build command, and passing this bill. Argument of port and set it to whatever set in the hub, and then it's sending the docker file path in the image name, the docker file path in image name. Come from these rules right here. So, let's say that. And then, it's come over here, and I'm going to commit those changes. So I'm going to go get them in changes.

And I'm going to push those. To that gets pushed up into get Docker Hub, is watching that waiting for the webhook, and if we come back into, our builds will see that we have a build kicked off. Okay? Or build as finished and you could see that it was successful. So it's roll down here into the build logs, a little bit. And I'm going to sue album. Sorry. Going to start at the top so you can see here. This is just a prebuilt hook, pre-built tests. Now, we're executing our build Hook and the build images

going to use port 8080. So that's where our custom build is being triggered. If we go back here and you see build image using port and then it's going to dump out the port, cuz we had pushed to latest. So it came into this then statement and we should Seaport And why port 8080? Because over here in our custom configuration of our Auto builds, we set port to 8080. Okay. so, What kind of took a look at how you can tie into custom build cycling in the build lifecycle show? You, there's a whole bunch of things you can do, but if you go to doctor, Advanced Auto

Builds an American spell Advanced, right? Going to be the first one. So, if you come to this website, In our documentation documentation is very good, but they can look down through this this document, and you can see all the environment variables that are set up for you, how you need to structure, how you need to structure, sorry of a fast-growing, how you need to structure year composed out and all kinds of things. So you can do it, you can do a lot, a lot of stuff with with your custom hooks files. Even at the end, you can push into another repository. And

and I think it shows it down here yet. So, even if you need to do branching and special cloning, you need to push the multiple Repose, you can do all kinds of stuff Within These custom hook valves, they're just shells grips. Okay? So the next thing I want to show you is webhooks. So I used a little test site, it's called webhook. Site and I've set up a Web book here already. And you can find the, the post URL right here. Somebody click copy that, and then we'll go back to in the hub, and let's go in the hooks.

And then you can set up the webhook right here, Cisco suit dockercon, What the hooks and then post a URL in there. That's to create and now we have our webhook here. Now what look to be triggered when anytime you push an image into your repository. So let's go back to our command line and we can do soccer tag. Let's do Mickey. Hello world. And we will tag the latest to pee McKee helloworld. Let's do 2.2.2. So I click that and now I'm going to do the doctor push. Andy McKee 2.2.2

and go ahead and push that. Okay, that was pushed. Now, if we come back here and look at our tags, We could see that we have a 2.2.2 image. Then if we come over here to webhooks, let's take a look at these. Hope you the history here and we could see. We we just did a push. And let's go check out here and we could see we've gotten pushes they come into the Web book. We send messages into the web for can hear. You could see the raw data. So this is a awesome way to

connect into other servers are instances, are clouds in your CIA and then CD pipeline. So if you're looking to distribute your images to another repository, you can use what Hooks or if you want to update Canary Services, those type of things. You can send a Web book after an image has been pushed. Okay, let's do a quick little review. So we start out taking a look at continuous integration. And what that was that we took a look, at the way, how does continuous integration look at how you create a repo and then how you connect that repo? I

need to get home. And then we took a look at how you can set up Auto bills and auto tasks. And we did that very simply and built-in Hub. And then we took a look at how you can connect into that life cycle to build and how you can do. A custom builds custom pushes a different repos in those type of things and then we kind of finished it out with webhooks. We took a look, how you how you can set up a white polka.and Hub and how that way poke gets fired, once an image is pushed into the repository, that way you can connect in other cicd systems and the cloud. So, thank you so much for joining

me. I really appreciate your time, make sure you check out all the other talks and please stay safe out there.

Cackle comments for the website

Buy this talk

Access to the talk “How to Build and Test Your Docker Images in the Cloud”
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free

Ticket

Get access to all videos “DockerCon 2020”
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free
Ticket

Interested in topic “IT & Technology”?

You might be interested in videos from this event

September 28, 2018
Moscow
16
177
app store, apps, development, google play, mobile, soft

Similar talks

Erika Heidi
Senior Technical Writer at DigitalOcean
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free
Lukonde Mwila
Senior Software Engineer at Entelect
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free
Brandon Mitchell
DevOps Solutions Architect at BoxBoat
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free

Buy this video

Video

Access to the talk “How to Build and Test Your Docker Images in the Cloud”
Available
In cart
Free
Free
Free
Free
Free
Free
Free
Free

Conference Cast

With ConferenceCast.tv, you get access to our library of the world's best conference talks.

Conference Cast
735 conferences
30224 speakers
11293 hours of content