Make Docker easier with Makefiles! • #docker #automation #devops #scripting

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's take a look at how you can streamline your Docker development process using make files okay so in recent videos on my channel we've been focusing a lot on Docker container images and how to publish those to different destinations but one of the things that can really help streamline your Docker development environment or development environment for pretty much anything you're working on is using make make is a an open source tool that you can use to chain automation commands together to do certain things if you've ever used something like npm if you were to live in the JavaScript ecosystem you can you can specify commands in package.json to do things like build your project to update your project you can chain these things together in very interesting ways to make it so this way you have a single like one line command that you run well we're gonna do the same thing with make now before you can do this you'll have to have make installed on your computer it's pretty much for Linux you can install it on Windows under certain environments but you likely if you're using a Windows machine you're going to want to use the windows subsystem for Linux so I'll leave instructions in the description below on how to install those but for if you have them installed we can start by creating what's called a makefile make file just like a like a Docker file has no extension at the end of it it simply is make file with nothing else there and the way you would specify a script inside of a make file is you say you would say the name of the command you want to enter so in this case I'll say hello and then I'm going to put a bash command in here so we'll say Echo hello world like that and now what I can do is I can open my terminal and type in make hello so make is the the actual binary that's gonna be executed hello is the name of the command that's defined inside of my make file and you can see it it shows you the actual output itself but it simply outputs hello world it runs whatever bashes inside of there so now we can also specify variables within our make files as well so say for instance I want to say hello somebody's name I can type in a name here and then I'll just put my name in which is Brian and then we can swap that out here by using a dollar sign open curly back bracket bracket and then our name variable here so now when I run make hello you can see it says hello Brian instead of hello world right so earlier I had mentioned that using make you can change certain commands together which can can create some pretty cool automations so let's take a look at how to do this now I'm going to type in world because we gotta stick with the Hello World theme it's kind of like you know content creator law I guess when it comes to programming and we'll just Echo out this is a chain command right we're just echoing something else out now if I type in make world you can see it it just runs that command now if I actually want to run something like hello before world I can simply type in hello as the name of the command that I want to run before World directly after this colon here so now if I save that and I run make world you can see it it now says hello Brian as well as this is a chain command so what's happening is when you run this world command make is going to look at the commands right after it and run those first so in this case it ran the hello command first and then it ran the world command so now let's see how we can use this logic to do some pretty interesting and cool stuff when we're working with Docker container images specifically around building so let's start by creating a build command and we'll just say Docker build and then our and then our tag we've been working with so far is again since we're publishing up to dockerhub Brian MMO 2 or your username within Docker hub forward slash hello Docker hub and just latest for the version right so now if I do something like make build oh forgot something here we got to do a period and then a t i can't just specify the name there so now if I run make build we can see I'm actually building the container image and it's already pulled in it's already pulled in the name so instead of having to say dockerbuild dot T and then the name of the image itself I could just run make build every single time and it's going to publish that image out now what happens if we want to specify the the name of the image and the name of the tag I can actually create variables up here so we'll say image is going to be equal to Brian mmo2 forward slash hello or I'm sorry forward slash hello Docker hub and then for our tag name let's just make that latest like that and then now what I can do is I can swap these out here so instead of typing in my entire name I can just type in image and then colon tag and this is going to do essentially the same thing and let's test this out by saying uh make build or make build okay and it did exactly the same thing if I run up you can see here's the actual command that it ran it pulled in the name of the image and then the version number and we didn't have to manually type that in here either so again now if we want to publish this here's an interesting one we can do I can type publish as the name of the command and then say docker push and then same thing just specify image and then colon tag using those variables above but we always want to build the latest version of our code so now we can actually chain the build command in here first so what's going to happen is when we run make publish we're going to first build the container because that is the first command in the series in this series of commands that we're running and then it's going to finish off by running the push and publish the latest version of our container up into Docker hub so we can see there was the build and now here is the push that was run right after it was finished building the latest version of our code another common one that you might run if you're working within Docker a lot is you can use run and chain the build in there as well so Docker run and then we'll say our image name followed by our tag name and what this is going to do is every time you say make run this is going to build the latest version of the code and then run it just like we got this hello world here so now if I come in here and sip in hello from makefile and save that I can say make run and it's going to build the latest version and then go ahead and run that so now we have hello from make file instead of hello world hopefully by now you have a good understanding on how you can use make files to help improve your Docker development process if you've ever used make files before do me a favor let me know in the comments below what your specific use case was and if you enjoy this video you might like my previous video where I show you how to publish Docker images into GitHub container registry and with that I'll see in the next one bye-bye
Info
Channel: Brian Morrison
Views: 6,287
Rating: undefined out of 5
Keywords: makefiles, docker, docker workflow, docker automation, docker tutorial, what is docker, docker tutorial for beginners, docker container, docker for beginners, learn docker, dockerfile, docker images, docker container tutorial, docker hub, docker crash course, what is docker container, docker containers, docker run, docker desktop, containers, getting started with docker, programming, container, docker basics, devops, makefile, image
Id: 44EqIY7v5xM
Channel Id: undefined
Length: 6min 45sec (405 seconds)
Published: Thu May 18 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.