Check out a free preview of the full Complete Intro to Containers (feat. Docker) course:
The "Node.js on 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 create a Node.js container that uses Debian instead of Ubuntu after mentioning that there is a wide variety of containers using different libraries and laguages. Debian is used instead of Ubuntu because Node images were created in Debian.

Get Unlimited Access Now

Transcript from the "Node.js on Docker" Lesson

>> So we're gonna move on to node.js on Docker because I'm a node developer and that's what I like, and so you're stuck cuz I have the microphone. But pretty much everything that I'm gonna teach you here, one, you don't really need to know Node that much. I'm gonna give you all of the code and not necessarily expect you to understand it.

[00:00:16] And two, this could be applied to Ruby, it could be applied to Go, it could be applied to Java, Cobalt, Pearl, I don't know, whatever suits your fancy. I'm not gonna shame. But just to kind of start getting into some of these other flavors of containers that might be useful to you, in particular, the node one because we are gonna be using that one all day.

[00:00:37] So we're here in MacOS mode right now. And I'm gonna say docker run dash it. And I'm gonna say node, which isn't the official node container that Docker certifies as official. These are actually built by a company called NodeSource, wonderful people that do really great node consulting. And they make wonderful containers, they're experts in it, that's why I rely on them and I don't do it myself.

[00:01:04] And then here, if I did node, this would run latest, which I think would be the same as what I'm gonna tell you to do now. But again, I wanna kind of freeze in time, right? Just like you pin your dependencies before you send them in production, that's why I'm gonna give you the correct tag here.

[00:01:19] So I wanna run node 12, and then I want it to be tied specifically to Debian stretch. So I'm gonna say 12 dash stretch. So actually, that looks like I don't have that locally, so it's actually gonna go out and pull that.
>> Could you help me understand what do you mean by tying node to Debian stretch?

>> Sure. So whenever you run a Docker container, There's multiple versions of things going to it, right? And the thing that I'm gonna care in this particular case with the node image, the two things that I really care about the versions of is I care about what version of Linux it's on and I care what version of Node it's on, right?

[00:02:02] So the 12, that's node 12, that makes sense. Stretch is tying it to a specific version of Debian, which I believe is Debian seven. Don't quote me on that, cuz I don't really know Debian very well. Now, why are we doing Debian versus Ubuntu? That is just what they build the Node images with, right?

[00:02:18] I think you can get it on Bionic and other versions of Ubuntu, but by default it's on Debian.
>> It is kind of like a mash up on those two.
>> Yeah, so actually literally the next session I'll be talking about tags, which is what this is. But suffice to say it's arbitrary.

[00:02:33] So whoever creates the container chooses what the tags are called. So they could have called it stretch dash 12. They could have called it whatever they wanted to. That makes sense?
>> Yeah.
>> Cool.
>> So stretch is just a name does not have any?
>> It's a really easy way to remember the version of Debian, right?

[00:02:51] Again, like I can't remember what the numbers of what Debian version we're on, but I know that Stretch is the latest one, latest LTS, that is. Does that make sense?
>> Yeah, I just wasn't sure if Stretch was a term for latest or something.
>> It's not, no, it's specifically for Debian.

[00:03:08] It's like we've been using Ubuntu Bionic this whole time, right, which is 18.04, that's what Stretch is for Debian.
>> Thank you.
>> Yep. So we got, looks like two more layers that it's gonna download here very quickly.
>> Brian, do you want us to download this image, too?

>> Yeah, probably. Yes, the answer's yes cuz we'll use it several times throughout the rest of the course. Then, it has to go extract everything and then reapply everything, so it takes a bit of processing. So okay, we downloaded the image, it pulled it and executed it, and now it drops us into some sort of REPL, right?

[00:03:47] REPL being like a, god, what does REPL stand for? I'm sure someone here knows. Anyway, it stands for something, R-E-P-L. I'm sure there's nine people on the chat saying it stands for this.
>> Read, Evalue, Print, Loop.
>> Yep, Read, Evaluate, Print, Loop, there it is. And surprise, it's a JavaScript, right?

[00:04:14] So I can say console dot log x, right? And it'll do that, or 2 plus 2, whatever, right? So this dropped us into the node REPL inside of a Debian Stretch Linux, right? Which may or may not be what you're expecting. But like I said, the container gets to define what command actually gets run.

[00:04:36] So this drops up into a REPL, which stands for read, execute, print, and loop, right? For node js. So if I just say something like console dot log x, it's gonna log out x, right? Normal JavaScripty kinda stuff, right? If you just do it on your computer and you just write node, this is what it does for you.

[00:04:54] Like I was telling you before, the containers themselves get to decide. If I don't specify command, which you can see up here, right there, I didn't specify a command, right? So it does whatever it defaults to, in this case, it's like I'm gonna put you into the node REPL because I've no idea what you actually want to do, okay?

[00:05:13] So that's what this does here. I see the exit. There we go. So hit Ctrl+C twice, that'll get you out of the REPL. And then, it finishes the container at that point, right, because that's the CMD that it was designed to do. But if I actually wanna be dropped into just the Linux part of it, I can say bash, right?

[00:05:36] And now, I'm inside of this container. But as opposed to the other ones, first of all, if I say cat /etc/issue, you can see I'm on, looks like it's Debin nine is what stretch is. I was wrong, I thought it was seven. Any case, that's what kind of Linux we're in.

[00:05:53] And Ubuntu is based on Debian, so everything's gonna feel very, very familiar to you. But what's cool about this one if I say node dash v, right, now it has Node installed because I got the Node container, okay? So you can see here, I have Node 12, which is exactly what I asked for.

[00:06:14] So that's kind of fun, right? So again, something I think is quite useful, too, is just knowing this cat /etc/issue thing, right? If you run Node, right, and I just run Node like this, which I'm not gonna do right now. You might not know that this is Debian, right?

[00:06:37] I don't know if it's a faulty assumption, but I just assume most things are Ubuntu because that's what I use. But in this particular case, they decided to go with something else. But this is a good way to kinda say, okay, where am I, what am I doing, what's the lay of the land there?

[00:06:53] We'll go into later which Linux distributions you can select. But I mean, the sum of the story is choose the one that you're most comfortable with. All of these are really good. Red Hat Linux is a good one. Mint, Alpine, Debian, Ubuntu, they're all valid choices just depending what you wanna do.