Complete Intro to Containers, v2

Running JavaScript on Docker

Complete Intro to Containers, v2

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

The "Running JavaScript on Docker" 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 runs images for distributions of JavaScript runtimes, including Node, Deno, and Bun. He also shares the Docker commands for other environments, including Ruby, Go, Rust, PHP, and Python. The benefit of these images is the ability to get an environment up and running quickly for experimentation without following complex installation instructions.

Preview
Close

Transcript from the "Running JavaScript on Docker" Lesson

[00:00:00]
>> Brian Holt: Most of us are developers, or many of us are developers, so I'm trying to keep this kind of focused around development and developer needs. So let's do some Node stuff, right? Could be fun.
>> Brian Holt: So do docker run -it --rm node:20.
>> Brian Holt: What`s kinda cool about this is, where am I right now?

[00:00:34]
I am inside of Node, right? So if I say console.log.
>> Brian Holt: Right, this is directly inside of the Node.js repl at the moment. This is what Node does if you don't give it a file to run, right, it drops into the repl. How useful is this? I'm gonna say, not at all, right?

[00:00:59]
I had never used the Node.js repl, why would I [LAUGH]? Maybe some people do. It's not a way of interacting with JavaScript that I'm super interested in doing.
>> Brian Holt: There we go.
>> Brian Holt: So that's kind of interesting, there is a container out there. It's the Node container, it's maintained by Docker itself.

[00:01:19]
Not all of them are, but this one happens to be.
>> Brian Holt: What operating system do you think that's running on? The correct answer to that is, you probably don't care, [LAUGH] right? But if you are interested, you can just say cat. That's the issue. I didn't mean to do that, I meant to say node:20.

[00:01:46]
>> Brian Holt: And you can see it is running on Debian 12. It's kinda interesting, right? You'll find that a lot of these end up running on Debian. It's a very popular way of running containers, but for good reason. And again, if you wanna just hop in there and actually start messing around.

[00:02:06]
If I just put bash there, now that's gonna connect me into the container, running bash. So now I can do whatever I want. But now I have node available in here because it's the node container. They've installed it there for me so I can do. Node has npm, it has all the stuff that you would need to run node.

[00:02:24]
It's kinda cool, right?
>> Brian Holt: Now, what happens if I wanna run node with Alpine instead of with Debian? Well, as you might imagine.
>> Brian Holt: 20-alpine.
>> Brian Holt: Runs Node.js, but runs it on Alpine instead of running it on Debian. So they'll have a variety of ways for you to be able to run Node.

[00:02:57]
Do I have a link on there, I might. Let's go look, Docker images, next one. JavaScript on Docker. I think this link, yeah. So if you look at this, this is the official Docker Hub page for it. You can see, there are so many different images for Node.js.

[00:03:20]
This is for Alpine. Bookworm, I think, is a release of Debian, right? Certainly, bullseye is slim. So there's Debian, which is like full fat Debian, right? And then there's slim. So they take the Debian container and they slim it down to just the bare necessities. It goes from being 900 megabytes for the full Debian installation to being, I'm guessing here, 200 megabytes for the slim installation.

[00:03:51]
It's much smaller.
>> Brian Holt: What else is on here? Iron is like the name of what 20 is. So the name of stable node releases get assigned a metal or a periodic element. Iron, I think, is version 20. Anyway, we can go on and on. You can see, there's a lot of different images that you can use to install Node.js here.

[00:04:20]
>> Brian Holt: Cool, so that's goodness, that's pretty fun.
>> Brian Holt: What other ways could we run JavaScript on the server? And if your answer is Deno, you are correct. Docker run -it denoland/deno. We're gonna run it with CentOS, which is just another distribution here that we could be talking about.

[00:04:49]
1.42.4.
>> Brian Holt: Welcome to Deno. Pretty cool. How many of you have written Deno before? I have not. I love JavaScript, I've written extremely little Deno. It's just another way of running JavaScript on the server. But it's really cool that I didn't have to go learn how Deno is made.

[00:05:17]
I don't have to go set it up. I don't have to understand anything about it. I can just run their container, and it works. You might wonder, why is it just Node whereas this has denoland/deno? Anything that Docker maintains itself won't have a slash, right? So Node is maintained by Docker.

[00:05:36]
Ubuntu is maintained by Docker. Deno is not maintained by Docker, it's maintained by the Deno people themselves. So Denoland is their username, /deno is the name of the project. It's like GitHub repositories, right? That's why there's a slash there. If I do this again and say deno, this will actually put me into the repl for Deno 142.4, which is kinda cool as well, right?

[00:06:07]
>> Brian Holt: And this is still valid JavaScript, all still works.
>> Brian Holt: So that's cool. That's Deno. I imagine someone else probably thinks, well, you can do bun. You absolutely can do bun, let's do some bun. So oven/bun:1.1.3 bun repl.
>> Brian Holt: There we go. We are now in bun.
>> Brian Holt: It's all still JavaScript.

[00:06:49]
>> Brian Holt: So I'm curious, what distribution you think they're using? And I don't remember, so we're all gonna be surprised.
>> Brian Holt: Debian 11. Okay, yeah, bun is a very cool project. It's running using JavaScriptCore, which is the engine that powers Safari, as opposed to Node and Deno, which both run using V8, which is what powers Chrome.

[00:07:14]
So I'm not gonna go through all of these for you, but I took note of a bunch of them that I thought you might find interesting. You can see here there's a ruby one, golang, rust, php, python. These ones are all maintained by Docker themselves. Again, kinda my point here is that any run time or language that you wanna do, there almost certainly exists a Docker container for it.

[00:07:39]
Pretty cool, right? I'm enthused by this because I don't have to set up languages anymore, which is such a pain. I had to do a tiny bit of Rust work at my new company and I didn't have to set up Rust. I was able to just run this command right here.

[00:07:55]
>> Brian Holt: It's cool.

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