Check out a free preview of the full Complete Intro to Containers (feat. Docker) course

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

Brian demonstrates how to build a Buildah container within a Docker container.

Preview
Close

Transcript from the "Buildah & Docker" Lesson

[00:00:00]
>> We are now running this container and I've exposed Port 3,000 here. So if we run a container in here, it will be exposed on port 3,000, okay? So then, we're gonna use Buildah to build a Buildah container inside a source here. So if you look, this has a Docker file, it's our index dot js.

[00:00:20]
If I say cat index dot js, you can see here, it's just our node service that we wrote a couple of chapters ago, okay? Now Buildah has a particular way of building containers that you can go in. It's kind of built to be built interactively. So rather than having a Docker file, you go and you say, okay, we're gonna start from here and then do this to the container.

[00:00:41]
And you do it just with the command line interactively. It's kind of a fun way to build containers. We're not gonna be doing that because it would take a bunch of time. And I'll leave you to do that if you're interested in doing Buildah. This is more just to introduce you to it.

[00:00:55]
What I'm gonna do instead is I'm gonna say buildah. And then, you can say build-using -docker-file. So Buildah knows how to read Docker files, which is pretty cool, right? Or if you don't wanna type build-using-dockerfile, they shortened that to bud, build-using-dockerfile. You tell it the file, which is dot slash Dockerfile.

[00:01:24]
And you're gonna give it a tag just like you would with Docker. And you're gonna say my-app-buildah. Whatever you wanna tag it, and then period. So from there, it's gonna go and install all the necessary things that you need. It's gonna go grab them off of Docker hub.

[00:01:51]
I don't know why it's flashing so much. So this will take a second cuz this is not gonna pull from the Docker cache, right? Cuz this is a product than Docker. So that downloaded node 12-stretch. You could also change this to node alpine, it'd be totally fine and it would take a little less time to download.

[00:02:12]
And this is gonna go piece by piece and build our Docker file, or build a container with our Docker file. So you can see there, it's running our npm install there. It's gonna run npm ci. Copy our node directory over. And there you go. We successfully built a Buildah container using a Docker file.

[00:02:49]
So let's do a buildah inspect. What did I call, did I call it my-app-buildah? I think I did. Same thing here. You can see all the various things it did. You can see all the layers that it did, so on and so forth. Okay? So there is some overlap between what Buildah can do and what do Podman can do.

[00:03:31]
It's not as clean cut as you might think it is. You can actually use Buildah to run containers as well, but you use it more to do the Docker run one command and then finish kind of scenario. Podman is more for I wanna run a web server and I want you to manage this for me, right?

[00:03:50]
Whereas Buildah can say, hey, do a thing with a container and then finish. So they kinda separate that out between Buildah and Podman. So what we could do here is we can say buildah run dash dash net host, my app. I have to do that thing first. You have to do this, sorry.

[00:04:12]
Buildah from my-app-buildah, like that. Cuz you have to get the container started first. So now, I have it started. Can I do like a buildah ps? Does it know how to do that? It does. Okay, so I can see here that I've started this. And I have, it's running in the background.

[00:04:35]
So the my-app-buildah-working-container. So this is the image, my-app-buildah, and then working-container's actually the executing container at this moment in time. And then now, what I can do is I can say, buildah run dash dash net host my-app-buildah. Or I just paste that in there from up there. my-app-buildah-working-container, which is what it called it right there.

[00:05:07]
And then, I can pass into it dash dash space bash. And this will execute that against the container which is going to drop me into the executing container. So now, I'm inside of a container which is inside of a container, right? So I'm inside of a Docker container which had Buildah installed, and then I used that to execute the container which is running inside of the same context.

[00:05:30]
So now, if I say cat/etc/issue, what do we expect to see? Debian, because that's what we built our container with. And now, you can see I'm here, I could say node index dot js, and everything will execute just fine. And it'll be great. So let's stop that, we'll exit out of here.

[00:05:52]
And I can say buildah, is it stop? [INAUDIBLE] I don't remember. Kill, maybe? Remove. Yep, so I can say buildah rm my-app-buildah-working-container. And that'll go and actually shut down the container from running. So that's kind of what Buildah can do for you. And like I said, there's some overlap with Podman, cuz Podman is built for executing containers.

[00:06:30]
Buildah's more, as it may sound, built for building containers. But there's some overlap in what they can do.

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