Complete Intro to Containers, v2

Tags & Docker CLI

Brian Holt

Brian Holt

SQLite Cloud
Complete Intro to Containers, v2

Check out a free preview of the full Complete Intro to Containers, v2 course

The "Tags & Docker CLI" Lesson is part of the full, Complete Intro to Containers, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian explains that tags allow you to run different versions of the same container. Omitting a tag during a docker run command implicitly applies the "latest" tag. The lesson also demonstrates additional features of the Docker CLI.

Preview
Close

Transcript from the "Tags & Docker CLI" Lesson

[00:00:00]
>> Brian Holt: We talked a little bit about tags. Let's talk a little bit more about tags. So far, I've just kind of been telling you to put the colon there and just making you go through it. A tag can be anything. You can put anything you want in the tag.

[00:00:13]
Notice that we were doing Jammy for Ubuntu, right? But if you go look in here, let's go look at Ubuntu in here.
>> Brian Holt: So Jammy is really just an alias for 22.04, but it's much simpler for my mind to remember Jammy as opposed to 22.04. So they do that so that you're able to kind of recall those as opposed to just having to remember the name of the number.

[00:00:43]
Mantic is their unstable one that they're doing, or development version that they're doing, and then Noble is the next stable one. I don't know if it's actually stable yet. I don't really keep so close up to date with what Ubuntu's releasing, but eventually, Noble will be the next release of Ubuntu.

[00:01:05]
It's always like Jammy jellyfish or focal fox, it's always alliteration for Ubuntu. You can see that they have various different architectures that they support, which actually ends up being really important because I'm on a MacBook, I have to pull arm compatible images. But Docker handles all of that for you.

[00:01:28]
But if someone releases a new container and they don't compile it in your particular flavor of instruction set, you'll have some issues. Because this is a MacBook it has Rosetta so it'll still run I'll just be a lot slower and a lot less efficient. But just something to keep in mind.

[00:01:48]
I'm sure with the new surfaces that Microsoft is releasing that are all ARM based will have the same issues as well. We talked a little bit that if you don't put anything there it's gonna assume that you meant latest, which is not always what you want.
>> Brian Holt: And, yeah, we talked about what Alpine Linux is, but we're gonna get really into depth with it.

[00:02:10]
Alpine Linux is basically the last time I taught this course was by far the smallest distribution of Linux, right? Not even close. Now it has some pretty stiff competition. There's like four or five distributions of Linux that are competing to be like the default container operating system. Still lots of people use Alpine.

[00:02:32]
It's a very well understood container, so people understand what to do with it. But anyway, we'll get to that here in a little bit.
>> Brian Holt: Yeah, this is a good pro-tip to just kinda keep in the back of your head. With your development container, so whatever you're using to develop stuff, use the full DB and all of it.

[00:02:51]
Don't use the slim one. Have it be 5 gigs and include all of your development tools. Do all the stuff that you need to do. And then when you ship stuff to production ship that in Alpine or discharge list or something like that so that you have less security surface area in your containers.

[00:03:10]
>> Brian Holt: Yeah, you'll get the best of both worlds.
>> Brian Holt: Okay, so that's tags, we did talk a little bit about the CLI, but we'll just talk a couple more about some more features of the CLI. This is my favorite demo, so we're definitely gonna do this. Make this small for just a second.

[00:03:39]
Well, so I'm gonna run this command, docker pull jterpin/hollywood.
>> Brian Holt: So I pulled it, what pull does, you can ignore the deprecation, just no one cares, is it all does is just pulls it into your cache, right? So it goes out to Docker Hub, it downloads it, and then it doesn't do anything with it.

[00:04:03]
Okay, and then now that I've pulled it into my cache, I don't have to wait for it to download. So I can say, Docker run Hollywood, and let's just make this full screen.
>> Brian Holt: So what this container is for is you run this on an airplane and you see who gets nervous.

[00:04:29]
It's not doing anything other than just running a bunch of random Linux commands. And it makes you look like a hacker, right? [LAUGH] It's amazing, right?
>> Brian Holt: Super funny to me.
>> Brian Holt: Yeah, it's called Hollywood because it does absolutely nothing.
>> Brian Holt: And then I think this is using screen to just divvy up your screen in a bunch of different ways, kind of fun.

[00:04:58]
So let's run that in the background, docker run, and as you remember, -dit is in the background. Name, I'm gonna call it hw for Hollywood, --rm, and then I'm gonna run jturpin/hollywood.
>> Brian Holt: Hollywood, okay, and now you can see I had this running in the background. You can docker pause hw, and you can see now that it is paused.

[00:05:35]
>> Brian Holt: And I can say docker unpause hw and lo and behold, it'll unpause it. And then docker kill hw. Why would you wanna do that? I don't know, I haven't actually really ever had a use case to pause a container, but you can. Figure it might be useful for someone.

[00:05:55]
We talked a little bit about docker exec, so I'm gonna run that in the background again. And I can say docker exec hw ps aux. So if I run this,
>> Brian Holt: Exec says, okay, connect to this container, hw, and then run this command. So now I'm seeing the output of everything that's running in that Hollywood container, right?

[00:06:26]
So this is what I was talking about if I run docker attach, docker attach hw, notice it actually drops me directly into the whatever is running in the foreground into that particular process. So now that I've hit CTRL+C, I've actually stopped it from running, which is not probably what I wanted.

[00:06:54]
>> Brian Holt: And then If I say docker ps, it should be gone. Yeah, see it's gone, which is you have to be careful with attach from that particular perspective. Usually, it's exactly what you want. Import/export, we talked about export that we exported it out into a tar file, right?

[00:07:12]
And then we used that later. Import, as you might imagine, is you have a container that exists outside of docker and you wanna import it to be used inside of docker. That's what Docker import would do. Docker history will show you the history of like what's happened with all the various different layers inside.

[00:07:32]
We'll talk about layers in a bit. But that'll show you when it was created, when it's been modified, all those kind of things.
>> Brian Holt: Docker info.
>> Brian Holt: It was just docker info. Got it, okay. Yeah, this is one that will show you that's actually what's It's available and how it's configured at the moment.

[00:07:57]
So we're not in debug mode, there's the proxy, blah, blah, blah. That can be useful for debugging purposes. This is a cool one that docker run -dit name, we're gonna run a Mongo container really quick, rm mongo. Okay, so I have Mongo running in the background now, which is MongoDB, in case you're wondering.

[00:08:29]
And I'm gonna say docker top my-mongo. This is gonna give me the output of like ps aux, right? That's what I've been doing over and over again. But you can see all that it's doing right now is running an instance of the Mongo daemon and with bind_ip_all.
>> Brian Holt: Kinda cool, right?

[00:08:55]
>> Brian Holt: Kill my-mongo.
>> Brian Holt: I don't think I have any, I do, okay cool. So let's say I wanted to get, this is all of my dead container, right? They're all status exited down here on the right. So, let's say I wanted to get rid of one of these, but not all of them.

[00:09:18]
I can say docker rm, blah, and that'll go through and actually remove just that one, as opposed to removing all of them at the same time. By the same token, I have docker images, right?
>> Brian Holt: Come on. Let's say, I don't know, I wanna get rid of this one.

[00:09:43]
You can say docker rmi, the I for images and I can just say I don't wanna have this in my cache anymore and it'll actually go through and delete those out of your cache. If you're done with it, you need to free up some storage but not all of it.

[00:09:57]
That's one way you could do it.
>> Brian Holt: Okay, Docker restart. probably no surprise to you that that will restart a container. Good to know. You can search for stuff on Docker Hub by saying Docker search this will show you everything that It has Python in it.
>> Brian Holt: And yeah, that's about all of the surface area of Docker that I tend to use on a monthly basis, probably.

[00:10:33]
It does more.
>> Brian Holt: And we'll talk about a few of them, right? But you can see here, there's a bunch of them.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now