Latest / CyberCode Academy / Course 31 - Dive Into Docker | Episode 7: Building, Running, and Syncing Flask Applications
Transcript
- 0:00Speaker 1: In the early twenty tens, software companies were losing literally
- 0:04Speaker 1: millions of dollars, and developers were burning, you know, countless
- 0:08Speaker 1: late night hours, all because of a five word phrase.
- 0:11Speaker 2: Oh, I know exactly which phrase you're talking about, right,
- 0:13Speaker 2: it works on my machine, the absolute bane of the industry.
- 0:16Speaker 1: Seriously, picture this. You write a brilliant piece of code,
- 0:19Speaker 1: maybe a Python web application, right, and it runs flawlessly
- 0:25Speaker 1: on your laptop. So you hand it off to a colleague,
- 0:27Speaker 1: or you deploy it to a production server, and the
- 0:30Speaker 1: entire system just instantly crashes.
- 0:33Speaker 3: Yeah, and usually for the dumbest reasons too, exactly because
- 0:36Speaker 3: your laptop has like a specific version of Python, or
- 0:39Speaker 3: a specific hidden system file or some environment variable that
- 0:43Speaker 3: the server just doesn't have.
- 0:45Speaker 1: So today we are diving into the tool that effectively
- 0:48Speaker 1: killed that five word phrase forever. We are mastering the
- 0:52Speaker 1: Docker command line interface.
- 0:54Speaker 2: And you know, overcoming that phrase required a really fundamental
- 0:57Speaker 2: shift in how we think about software deployment, because we
- 1:00Speaker 2: aren't just shipping.
- 1:01Speaker 1: Code anymore, right, We're shipping everything, exactly.
- 1:04Speaker 2: We are shipping the entire environment, the code, the dependencies,
- 1:08Speaker 2: the filesystem, all of it packaged into a single unbreakable
- 1:12Speaker 2: box that behaves exactly the same way regardless of what
- 1:16Speaker 2: hardware runs on.
- 1:17Speaker 1: Well, welcome to this deep dive. I'm your host, and
- 1:19Speaker 1: today we're going to build a mental framework for mastering
- 1:22Speaker 1: this ecosystem from the ground up. We'll walk you through
- 1:26Speaker 1: creating the blueprints for these unbreakable boxes, bringing them to
- 1:29Speaker 1: life as running applications, creating like wormholes to live at
- 1:34Speaker 1: your code without rebuilding everything, and even teleporting inside them
- 1:37Speaker 1: to troubleshoot when things inevitably get.
- 1:40Speaker 2: Weird, which they always do. And to get to that
- 1:42Speaker 2: level of mastery, we really have to start at the
- 1:44Speaker 2: foundational layer, which is how we actually communicate with the system,
- 1:48Speaker 2: and that means looking closely at the CLI, the command
- 1:51Speaker 2: line interface itself.
- 1:52Speaker 1: Okay, so let's set the stage. Visualize your terminal. You're
- 1:55Speaker 1: sitting at your keyboard, you've just installed the tool, and
- 1:57Speaker 1: you type Docker help. Now, if you've ever were used
- 2:00Speaker 1: a massive developer tool before, you might brace yourself for
- 2:03Speaker 1: an overwhelming, just endless scroll of hundreds of arcane commands.
- 2:07Speaker 2: Like a wall of text.
- 2:09Speaker 1: Yeah, a wall of text, but you don't get that here. Instead,
- 2:12Speaker 1: you see a neatly categorized list of what they call
- 2:15Speaker 1: management commands. So you see docker image, Docker container, Docker volume, right,
- 2:22Speaker 1: and that.
- 2:22Speaker 2: Clean organization that actually wasn't always there, which I think
- 2:25Speaker 2: is a crucial piece of context for anyone learning this.
- 2:27Speaker 1: Oh really, it used to be a mess.
- 2:29Speaker 2: Oh completely. Prior to version one point thirteen, there were
- 2:32Speaker 2: no management commands. It was just a massive flattened list.
- 2:35Speaker 2: So you had Docker, bild, Docker run, Docker and high
- 2:39Speaker 2: all just mixed together. That sounds awful, it was, And
- 2:42Speaker 2: as the technology evolved, they added networks and volumes and orchestration,
- 2:47Speaker 2: and that flat list became just an absolute nightmare to
- 2:50Speaker 2: learn and navigate. So by introducing this categorized structure, grouping
- 2:55Speaker 2: everything logically under the object it manages, they made the
- 2:58Speaker 2: system inherently discoverable.
- 3:00Speaker 1: Discoverable meaning like you don't have to memorize everything up
- 3:02Speaker 1: front exactly.
- 3:03Speaker 2: If you want to know what you can do with
- 3:05Speaker 2: an image, you just type Docker image help and the
- 3:07Speaker 2: system only shows you the subset of commands relevant to
- 3:10Speaker 2: that specific object.
- 3:11Speaker 1: Okay, so let's actually start with that exact object, because
- 3:14Speaker 1: before we can run our unbreakable box, we have to
- 3:17Speaker 1: draft the blueprint for it. And in this world, that
- 3:19Speaker 1: blueprint is called an image, so we need to tell
- 3:22Speaker 1: the system to build it. Sitting at your terminal, you'd
- 3:25Speaker 1: type Docker image build doth t web one at ending
- 3:29Speaker 1: with the period.
- 3:30Speaker 2: Yes, And that period at the end is not a typo.
- 3:33Speaker 2: People miss that all the time.
- 3:35Speaker 1: I've definitely missed it.
- 3:36Speaker 2: It's actually the anchor of the whole command. The period
- 3:38Speaker 2: tells the system look right here in my current working
- 3:41Speaker 2: directory for a file literally called docker file, and the
- 3:45Speaker 2: system just reads that file from top to bottom, executing
- 3:48Speaker 2: its instructions to construct the environment.
- 3:49Speaker 1: Okay, and let's talk about that dosh t web one part.
- 3:52Speaker 1: The dosh t stands for tag, right. I'm assuming that
- 3:55Speaker 1: if we don't give it a friendly name like web one,
- 3:58Speaker 1: the system is just going to generate some massive, unreadable
- 4:01Speaker 1: alphanumeric string.
- 4:02Speaker 2: It does. It generates a cryptographic hash, usually SAHA two
- 4:05Speaker 2: five six, And I mean imagine trying to tell your
- 4:09Speaker 2: coworker to deploy image seven eight F nine C two
- 4:12Speaker 2: e and so on.
- 4:13Speaker 1: Yeah, nobody's doing that.
- 4:14Speaker 2: No, it's impossible. Tagging it simply maps a human readable
- 4:18Speaker 2: string to that underlying hash.
- 4:20Speaker 1: Okay, so you hit enter on that build command. The
- 4:23Speaker 1: terminus starts spitting out steps. Step one might be pulling
- 4:26Speaker 1: down a base operating system like a minimal version of
- 4:30Speaker 1: Linux with Python installed. Step two might create a folder
- 4:34Speaker 1: called app. Step three copies your local code into that folder.
- 4:38Speaker 1: But the interesting part here is that each of these
- 4:40Speaker 1: steps generates something called a layer.
- 4:42Speaker 2: Right, and layers are the absolute secret sauce of this technology.
- 4:47Speaker 2: When an instruction in your docrophile executes, it captures the
- 4:51Speaker 2: changes made to the file system and saves them as
- 4:54Speaker 2: a distinct read only layer.
- 4:56Speaker 1: Okay, think of an image like an old school two
- 5:00Speaker 1: animation cell.
- 5:01Speaker 2: I like that.
- 5:02Speaker 1: Yeah, So you have a clear piece of plastic with
- 5:04Speaker 1: the painted background. You lay another clear plastic sheet on
- 5:07Speaker 1: top with the character's body, then a final plastic sheet
- 5:09Speaker 1: on top with the character's facial expression.
- 5:11Speaker 2: Right.
- 5:11Speaker 1: If the animator wants to change the facial expression, they don't,
- 5:14Speaker 1: you know, repaint the background or the body. They just
- 5:16Speaker 1: swap out the very top transparency. That's exactly how these
- 5:19Speaker 1: layers work, right. They are stacked read only file systems.
- 5:22Speaker 2: That captures the immutability perfectly. Because they read only transparencies,
- 5:27Speaker 2: they could be cashed and reused. So if you run
- 5:29Speaker 2: that exact same build command a second time. It finishes
- 5:33Speaker 2: in milliseconds.
- 5:34Speaker 1: Because it's not actually rebuilding anything exactly.
- 5:37Speaker 2: Under the hood, the system calculates a cryptographic hash of
- 5:40Speaker 2: your files. It looks at the instructions and says, hey,
- 5:43Speaker 2: the hash of this source code hasn't changed. I already
- 5:46Speaker 2: have a transparency for this. It skips the execution entirely
- 5:49Speaker 2: and just snaps the existing layer into place.
- 5:51Speaker 1: But let's say I open my code editor, I find
- 5:54Speaker 1: a typo in my Python script, fix it, hit save,
- 5:58Speaker 1: and then I run the build command again.
- 6:00Speaker 2: Okay, so the hashing algorithm detects the change in your
- 6:02Speaker 2: Python file. The system will use the cash transparencies for
- 6:05Speaker 2: the base operating system and the folder creation. But the
- 6:08Speaker 2: moment it reaches the step where it copies your code,
- 6:10Speaker 2: it says, wait, the hash is different because the text change, right,
- 6:14Speaker 2: So it throws away the old transparency for that step,
- 6:17Speaker 2: generates a new one, and crucially, it must also rebuild
- 6:21Speaker 2: every single layer that comes after it. Oh wow, Yeah,
- 6:24Speaker 2: this makes ordering your instructions incredibly important for performance. You
- 6:28Speaker 2: put the things that change the least at the very
- 6:30Speaker 2: top and the code that changes constantly at the very bottom.
- 6:33Speaker 1: Okay, that makes sense. So we've got our fully stacked
- 6:37Speaker 1: animation cell, our image sitting on our laptop, but the
- 6:41Speaker 1: whole goal was to cure the works on my machine syndrome.
- 6:45Speaker 1: How do we get this blueprint off our laptop and
- 6:48Speaker 1: out to the rest of the world.
- 6:49Speaker 2: You push it to a registry, which is essentially just
- 6:52Speaker 2: a cloud storage locker for images. You start by authenticating
- 6:55Speaker 2: your terminal using the Docker log in command. The CLI
- 6:58Speaker 2: takes your credentials and securely stores an authentication token in
- 7:02Speaker 2: it can fig file on your host machine.
- 7:05Speaker 1: Nice, so we don't have to type our password every
- 7:06Speaker 1: single time we want to share something exactly.
- 7:09Speaker 2: Next, you need to map your local image to your
- 7:11Speaker 2: cloud identity. You use the Docker image tag command to
- 7:14Speaker 2: rename your local web one to include your unique username,
- 7:17Speaker 2: something like your username web one dot latest okay, and
- 7:21Speaker 2: once the image carries your name space, you simply run
- 7:23Speaker 2: Docker image push followed by that.
- 7:25Speaker 1: Name, and the system breaks it down and uploads those
- 7:28Speaker 1: individual layers, which is great because once it's safely up
- 7:31Speaker 1: in the cloud, I definitely want my heart Drek space back,
- 7:34Speaker 1: so I just type Docker image are arm to remove
- 7:36Speaker 1: it locally.
- 7:37Speaker 2: Yep.
- 7:37Speaker 1: Keeping things tidy, okay, So the blueprint is stored safely
- 7:40Speaker 1: in the cloud. But you know a blueprint is completely static.
- 7:44Speaker 1: You can't execute a blueprint. We need to bring this
- 7:46Speaker 1: code to life.
- 7:47Speaker 2: And this is the critical transition from the Docker image
- 7:50Speaker 2: commands to the Docker container commands. Specifically, we're talking about
- 7:54Speaker 2: Docker container run and image is the resting state, but
- 7:58Speaker 2: a container is the running, eating execution of that image.
- 8:01Speaker 1: So let's dig into the mechanics of spinning it up.
- 8:04Speaker 1: If I just sit down and type Docker container run
- 8:06Speaker 1: web one, something super frustrating might happen. My app might
- 8:10Speaker 1: boot up, but the moment I try to stop it
- 8:12Speaker 1: by pressing control plus C on my keyboard, nothing happens.
- 8:16Speaker 1: My terminal is frozen. Why does it ignore me?
- 8:18Speaker 2: Because a container is fundamentally just an isolated process running
- 8:22Speaker 2: on your machine. It is not a full virtual machine
- 8:25Speaker 2: with a graphical interface. If you don't explicitly tell Docker
- 8:29Speaker 2: to tether your terminal standard input to that isolated process,
- 8:33Speaker 2: the container has literally no idea your keyboard exists. It's deaf. Yes,
- 8:37Speaker 2: he can output text to your screen, but it can't
- 8:40Speaker 2: hear you typing at all.
- 8:41Speaker 1: And that's where our first set of vital flags comes in.
- 8:43Speaker 2: They it flags right. By passing the interactive in eighty flags,
- 8:47Speaker 2: that's it. You are building a bridge between your keyboard
- 8:50Speaker 2: and the container's standard input. So when you press c
- 8:53Speaker 2: R plus C, that interrupt signal is actively carried across
- 8:56Speaker 2: the bridge and delivered to your application, allowing it to
- 8:59Speaker 2: shut down gracefully.
- 9:00Speaker 1: Okay, so it is our safety tether. Now let's tackle
- 9:04Speaker 1: another real world problem. If this container is a perfectly
- 9:07Speaker 1: isolated box, how does my web application know the password
- 9:11Speaker 1: to my production database? Because I obviously don't want to
- 9:13Speaker 1: hard code a sensitive password into my blueprint where anyone
- 9:16Speaker 1: can see it.
- 9:16Speaker 2: No, definitely don't do that. You handle that dynamically at
- 9:19Speaker 2: runtime using the E flag, which stands for environment variable.
- 9:23Speaker 2: So when you run the container, you pass E database
- 9:25Speaker 2: password super secret, So the.
- 9:27Speaker 1: Application boots up, checks its local environment, and there's the
- 9:30Speaker 1: password just floating in memory, just for that specific run.
- 9:33Speaker 2: Yes, it's a clean, repeatable way to inject configuration or
- 9:37Speaker 2: secrets without altering the underlying image. Love it.
- 9:41Speaker 1: Now, what about networking. Let's say my Python web app
- 9:44Speaker 1: is programmed to listen on port five thousand. It's running
- 9:47Speaker 1: inside the container. If I open my laptop's web browser
- 9:50Speaker 1: and go to local host toy five thousand. The browser
- 9:53Speaker 1: is just going to say connection refused.
- 9:55Speaker 2: Because the container has its own isolated network interface by default,
- 9:59Speaker 2: it's port completely walled off from your host machines port
- 10:02Speaker 2: five thousand. To punch a hole through that wall, you
- 10:04Speaker 2: use the DAPPI flag for port mapping.
- 10:06Speaker 1: Let's visualize that typing. We do natch p five thousand
- 10:09Speaker 1: point five zero zero.
- 10:10Speaker 2: The syntax is always host machine on the left, container
- 10:13Speaker 2: on the right. You killing the engine, take port five
- 10:15Speaker 2: thousand on my physical laptop and silently forward any traffic
- 10:18Speaker 2: it receives straight into port five thousand inside the container.
- 10:22Speaker 1: Okay, let's push that further. What if I want to
- 10:24Speaker 1: run two instances of this exact same application on my laptop.
- 10:28Speaker 1: Maybe I'm testing how they balance a heavy workload. If
- 10:31Speaker 1: I run the second container with nabby fee five thousand
- 10:34Speaker 1: point five zero zero, the system is going to throw
- 10:36Speaker 1: a massive error.
- 10:38Speaker 2: Oh yeah, a physical port on your host machine can
- 10:41Speaker 2: only be actively bound by one process at a time.
- 10:44Speaker 2: The first container already claims your laptop's port five thousand.
- 10:47Speaker 1: So they'd crash into each other, right.
- 10:49Speaker 2: But the solution is elegant. Remember the left side is
- 10:51Speaker 2: the host for the second container. You simply map nabby
- 10:54Speaker 2: five zero zero zero one point five zero zero.
- 10:57Speaker 1: Ah.
- 10:58Speaker 2: Both containers are internally completely oblivious, running on their own
- 11:02Speaker 2: private port five thousands, but I access them externally on
- 11:05Speaker 2: port five thousand and five thousand and one. That's isolation
- 11:08Speaker 2: at its finest, exactly. Okay, so the app is running perfectly,
- 11:11Speaker 2: the ports are mapped, but we have a new problem.
- 11:13Speaker 2: My terminal is now completely hijacked by the live web
- 11:16Speaker 2: traffic logs. Every time I refresh the page, more tech
- 11:19Speaker 2: scrolls by. I can't type any new commands. I don't
- 11:22Speaker 2: want to shut the app down, but I want my
- 11:23Speaker 2: keyboard back. You need to kick that process into the background,
- 11:27Speaker 2: and you do that by adding the UAD flag for
- 11:29Speaker 2: detached mode instead of taking over your screen. The container
- 11:32Speaker 2: spins up outputs a long identification string just so you
- 11:35Speaker 2: know it started, and immediately returns your command prompt. It
- 11:39Speaker 2: runs quietly in the background.
- 11:40Speaker 1: Out of sight, but we still need to manage it.
- 11:42Speaker 1: We can type Docker containers to see a list of
- 11:45Speaker 1: everything running in the background, or we can use Docker
- 11:48Speaker 1: container stats to pull up a live, real time dashboard
- 11:51Speaker 1: showing you know CPU usage, memory consumption, network traffic for
- 11:56Speaker 1: that background process.
- 11:57Speaker 2: And if you realize you do want to see those
- 11:59Speaker 2: web traffic logs, you aren't locked out. You just use
- 12:02Speaker 2: Docker Container logs followed by the container's name, and if
- 12:05Speaker 2: you append the Tauchel flag for follow, it streams the
- 12:08Speaker 2: output in real time, exactly as if it were running
- 12:11Speaker 2: in the foreground.
- 12:12Speaker 1: But what happens if disaster strikes. Let's say this container
- 12:15Speaker 1: is detached, it's running on a production server. A bug
- 12:18Speaker 1: in the code causes the application to completely crash, or worse,
- 12:21Speaker 1: the server loses power and reboots. Is my web app
- 12:25Speaker 1: just dead in the water until I wake up at
- 12:27Speaker 1: three am and manually type the run command again.
- 12:30Speaker 2: Not if you utilize the Docker Demon effectively. The Demon
- 12:33Speaker 2: is the background service, the invisible engine that manages all
- 12:36Speaker 2: these objects. You can give the Demon instructions on how
- 12:39Speaker 2: to handle failures by using the restart on failure flag
- 12:42Speaker 2: when you initially run the container.
- 12:44Speaker 1: So the Demon acts as like a watchdog prefisely.
- 12:48Speaker 2: If the application process crashes, the Demon immediately notices the
- 12:51Speaker 2: process died unexpectedly and revives the container from scratch. If
- 12:55Speaker 2: the entire server reboots, as soon as the demon power
- 12:58Speaker 2: is back on, it checks it list of containers, sees
- 13:01Speaker 2: yours has a restart policy, and boots it back up.
- 13:04Speaker 2: It's the ultimate safety net for uptime.
- 13:06Speaker 1: This background running, auto restarting perfectly isolated container sounds like
- 13:10Speaker 1: a dream for a production environment.
- 13:12Speaker 2: It really is.
- 13:13Speaker 1: But let's look at this from a different angle. Let's
- 13:15Speaker 1: say I'm actively writing the code. I'm building a feature.
- 13:18Speaker 1: I notice a typo in a headline. I change the text.
- 13:20Speaker 1: I hit save. If I have to stop the container,
- 13:24Speaker 1: run the build command to generate a new image layer
- 13:27Speaker 1: and spin up a brand new container. Just to see
- 13:29Speaker 1: a single text change. My productivity is going to plumb it.
- 13:32Speaker 1: It's just too much friction.
- 13:33Speaker 2: Yeah, rebuilding images is fantastic for immutable deployments, but it
- 13:37Speaker 2: is a terrible workflow for active development. You need a
- 13:40Speaker 2: way to bypass those read only layers entirely, and the
- 13:44Speaker 2: system provides this through a mechanism called volumes.
- 13:47Speaker 1: Okay, let's translate the command for that. I pass a
- 13:49Speaker 1: dash V flag. The syntax looks like dhvpwd dot app.
- 13:54Speaker 1: So PWD is my current working directory on my laptop,
- 13:57Speaker 1: My source code and app is the Destiny Nation folder
- 14:00Speaker 1: inside the container.
- 14:02Speaker 2: Right by issuing that command, you were telling the engine
- 14:05Speaker 2: to ignore whatever files are baked into the app folder
- 14:08Speaker 2: of the image. Instead, it mounts your host directory directly
- 14:11Speaker 2: over it.
- 14:11Speaker 1: It's like a magical two way mirror or a wormhole.
- 14:14Speaker 1: The container looks into its app folder, but it's actually
- 14:17Speaker 1: seeing the live file sitting on my laptop's hard drive.
- 14:19Speaker 2: Wormhole captures the behavior perfectly. If you combine this volume
- 14:22Speaker 2: mount with your framework's native live reload features, say by
- 14:26Speaker 2: passing an environment variable like flaxybud one, you unlock a
- 14:29Speaker 2: totally seamless workflow. You open your code editor on your
- 14:32Speaker 2: host machine, you change the headline, you hit save.
- 14:35Speaker 1: And the file changes on my hard drive. The wormhole
- 14:38Speaker 1: instantly exposes that change to the container. The web framework detects,
- 14:42Speaker 1: it restarts the server internally, and I just switched to
- 14:45Speaker 1: my browser and hit refresh. No rebuilding layers, just instant feedback.
- 14:51Speaker 2: And this reveals a major strategic pattern in modern engineering.
- 14:54Speaker 2: You rely heavily on volume mounts during local development to
- 14:58Speaker 2: maintain speed and agility, but when you are ready to ship,
- 15:01Speaker 2: you remove the volume, rely on the docker file to
- 15:04Speaker 2: solidly bake the code into a new image and push
- 15:07Speaker 2: that immutable artifact of production.
- 15:09Speaker 1: You get the best of both worlds exactly. Well, what
- 15:12Speaker 1: happens when the magical wormhole drops the ball? Because we've
- 15:15Speaker 1: all been there. You set up the volume, you hit
- 15:17Speaker 1: save in your editor, you eagerly hit refresh in the browser,
- 15:20Speaker 1: and you're just staring at the old code, nothing updated.
- 15:23Speaker 1: How do we figure out what's going wrong inside an
- 15:25Speaker 1: isolated black box.
- 15:26Speaker 2: Well, when you abstract the file system across multiple layers
- 15:29Speaker 2: of technology, edge cases emerge. To understand why this fails,
- 15:33Speaker 2: we need to look at how different operating systems interact
- 15:36Speaker 2: with Docker. Because underneath everything, Docker relies exclusively on the Linux.
- 15:40Speaker 1: Kernel, which is fine if I'm running an Abuntu laptop,
- 15:44Speaker 1: but I'm writing code on a Mac or Windows machine.
- 15:47Speaker 1: They don't have Linux.
- 15:48Speaker 2: Kernels, and that is the massive, hidden technical detail. When
- 15:51Speaker 2: you install this tool on Macro Windows, it secretly installs
- 15:56Speaker 2: a tiny, lightweight Linux virtual machine in the background to
- 15:59Speaker 2: add act as a bridge. So when you create a
- 16:02Speaker 2: volume Wormhole, your Mac file system has to translate file
- 16:06Speaker 2: save events across the virtual machine boundary, into the Linux kernel,
- 16:10Speaker 2: and finally into the container.
- 16:11Speaker 1: That is a lot of translation layers.
- 16:13Speaker 2: Now consider the base images we use. A lot of
- 16:16Speaker 2: developers love using Alpine Linux for their base image because
- 16:20Speaker 2: it is astonishingly small, sometimes just like five megabytes wow.
- 16:23Speaker 2: But Alpine uses very specific, stripped down internal tools. When
- 16:27Speaker 2: the Linux kernel tries to send a file change notification
- 16:30Speaker 2: using a subsystem called inotify, cross that VM boundary and
- 16:33Speaker 2: into an Alpine container, it sometimes just vanishes. The translation
- 16:37Speaker 2: layer drops the ball. The container literally does not know
- 16:39Speaker 2: you save the file.
- 16:40Speaker 1: So the fix is to abandon Alpine.
- 16:43Speaker 2: The most consistent fix for local development is to change
- 16:46Speaker 2: the first line of your Docker file. Instead of using
- 16:49Speaker 2: the ultra lightweight Alpine variant of your language, you switch
- 16:52Speaker 2: to the Slim variant, which relies on a more standard
- 16:55Speaker 2: distribution like Debian. The standard and notified tools in Debian
- 16:59Speaker 2: handle the CVM translation much more reliably.
- 17:02Speaker 1: Let me push back on that though. If Alpine has
- 17:05Speaker 1: this notorious bug with file watching on Mac and Windows,
- 17:09Speaker 1: why does anyone use it? Why not just use Slim
- 17:11Speaker 1: for everything and save yourself.
- 17:12Speaker 2: The headache Because in production you aren't live editing files
- 17:16Speaker 2: through a volume mount. You only encounter this bug during development.
- 17:20Speaker 2: Alpine's tiny size means it downloads faster, consumes less server memory,
- 17:25Speaker 2: and critically has a dramatically smaller surface area for security vulnerabilities.
- 17:29Speaker 1: Oh that makes sense.
- 17:30Speaker 2: Yeah, it's a fantastic production image. So knowing how to
- 17:32Speaker 2: toggle between them or how to spot via notified failure
- 17:35Speaker 2: is a crucial troubleshooting skill.
- 17:37Speaker 1: Okay, but before we go rewriting my blueprint to change
- 17:39Speaker 1: the operating system, I want proof. I want to prove
- 17:43Speaker 1: that the container actually isn't seeing my code changes. How
- 17:46Speaker 1: do I verify it's not just a dumb type on
- 17:48Speaker 1: my own code? Can I teleport inside the container and
- 17:52Speaker 1: look at the files with my own eyes?
- 17:54Speaker 2: Yes, you use what is arguably the most powerful diagnostic
- 17:58Speaker 2: command available, Docker container.
- 18:00Speaker 1: Okay, so my container, let's say it's named web one,
- 18:03Speaker 1: is running detached to the background. I open a new
- 18:06Speaker 1: terminal tab and type Docker container exec it web one bash.
- 18:11Speaker 2: By passing it to connect your keyboard and specifying BASH
- 18:14Speaker 2: or she as the command to run, you are injecting
- 18:16Speaker 2: a brand new interactive terminal session directly into the already
- 18:20Speaker 2: running container. You bypass the abstractions entirely.
- 18:24Speaker 1: It really does feel like teleporting into the matrix. So
- 18:26Speaker 1: the command prompt changes I'm now logged in as the
- 18:29Speaker 1: root user of the container. I can type standard Linux commands.
- 18:32Speaker 1: If I type as a LA, I see the file
- 18:34Speaker 1: system exactly as the application sees it.
- 18:36Speaker 2: And here is where you solve the mystery. You open
- 18:40Speaker 2: the file inside the container and you see that your
- 18:42Speaker 2: new code actually is there. The notified bug isn't the problem?
- 18:46Speaker 2: The volume worked? So why isn't the app updating?
- 18:49Speaker 1: Oh? If we're using Python, there's a notorious culprit here
- 18:53Speaker 1: hidden compiled files. The end in dot p key.
- 18:56Speaker 2: Exactly when Python executes your code, it compiles it into
- 18:59Speaker 2: a dot p fie file to make it load faster
- 19:01Speaker 2: next time. Sometimes, even if the source code updates via
- 19:04Speaker 2: the volume, the framework stubbornly holds onto the old compiled cache.
- 19:09Speaker 2: But because you are physically inside the container via the
- 19:11Speaker 2: exec command, you can just run a command to delete
- 19:14Speaker 2: those dot p files.
- 19:15Speaker 1: You just nuke the cash file, switch back to your browser,
- 19:18Speaker 1: hit refreshed, and boom, the new version of your apploads.
- 19:20Speaker 1: Mystery solved. But there is a trap here. Isn't there
- 19:24Speaker 1: a really frustrating side effect of teleporting in like this?
- 19:27Speaker 2: Yes, the permissions trap. By default, when you execute into
- 19:30Speaker 2: a container, you arrive as the root administrator. Let's say,
- 19:33Speaker 2: while you're inside troubleshooting, you run a command to generate
- 19:35Speaker 2: a new configuration file. Let's call it config dot txt.
- 19:39Speaker 1: Because of the volume wormhole, that file isn't just created
- 19:42Speaker 1: inside the container. It physically appears on my laptop's hard drive,
- 19:46Speaker 1: right next to my source code.
- 19:47Speaker 2: But here is the critical problem. Because you created it
- 19:51Speaker 2: as root inside the container, the file on your local
- 19:54Speaker 2: laptop inherits those root ownership privileges.
- 19:57Speaker 1: Oh man, there is literally nothing more infuriating than tabbing
- 20:01Speaker 1: back to your normal code editor on your Mac, trying
- 20:04Speaker 1: to OpenConfig dot txt and seeing a giant access denied
- 20:09Speaker 1: padlock icon.
- 20:10Speaker 2: We've all seen it.
- 20:11Speaker 1: Your own laptop won't let you edit or delete the
- 20:13Speaker 1: file because it thinks the system administrator owns it.
- 20:16Speaker 2: It completely breaks your workflow. To avoid this, you have
- 20:20Speaker 2: to give the container a fake ID that matches your
- 20:22Speaker 2: laptop's identity. When you run the exec command, you add
- 20:25Speaker 2: a userflag. On a Linux host or terminal, you can
- 20:28Speaker 2: dynamically pass your own user ID by typing user and
- 20:31Speaker 2: then substituting your user and group IDs like be use.
- 20:36Speaker 2: This forces the container to execute the command using your
- 20:38Speaker 2: local permissions, ensuring that any files generated through the wormhole
- 20:41Speaker 2: belong safely to you.
- 20:43Speaker 1: That is a life saver. All right, let's take a
- 20:45Speaker 1: breath and zoom out. Look at the mental model we've built.
- 20:48Speaker 1: We started with rock code. We drafted a Docker file
- 20:52Speaker 1: to build a layered cached image. We brought that image
- 20:55Speaker 1: to life as an isolated container, learn how to map
- 20:58Speaker 1: its network ports and how to detach it so it
- 21:01Speaker 1: runs quietly in the background. We created volume wormholes for
- 21:05Speaker 1: instantaneous live editing, and we learned how to teleport inside
- 21:09Speaker 1: to troubleshoot caching and permission traps.
- 21:11Speaker 2: It's a lot, but it fundamentally changes your relationship with
- 21:14Speaker 2: your machine. And beyond just deploying applications, I want you
- 21:18Speaker 2: to think about what this means for continuous learning. Think
- 21:21Speaker 2: about the friction of trying out a brand new programming language.
- 21:25Speaker 1: Normally it's awful. You want to try I don't know
- 21:27Speaker 1: Elixir or Go. You have to download a runtime, system,
- 21:30Speaker 1: path variables, install global dependencies, and basically risk polluting your
- 21:34Speaker 1: laptop with libraries you might use exactly once.
- 21:37Speaker 2: Right, But with this tool set, that friction drops to zero.
- 21:40Speaker 2: You don't install anything on your host system. You just
- 21:43Speaker 2: run a command to pull the official image for that language,
- 21:46Speaker 2: attach your terminal with the interactive flags, and you are
- 21:49Speaker 2: immediately sitting in a pristine, perfectly configured command prompt for
- 21:53Speaker 2: that language. You experiment, you test out the syntax, and
- 21:57Speaker 2: when you're done, you just exit. You just exit. Container
- 22:00Speaker 2: disappears and your laptop remains completely untouched. It transforms your
- 22:04Speaker 2: computer into an infinite risk free sandbox.
- 22:08Speaker 1: The ultimate playground for a curious mind. All right, before
- 22:11Speaker 1: we wrap up, here is a quick mental exercise for
- 22:14Speaker 1: you to lock these concepts in. Think about your own
- 22:17Speaker 1: current setup. What exact command would you type to start
- 22:20Speaker 1: a container? Force it to run quietly in the background,
- 22:23Speaker 1: and map port eighty eighty on your local laptop to
- 22:25Speaker 1: port eighty inside the container.
- 22:27Speaker 2: Remember you need to combine two specific flags we discussed,
- 22:30Speaker 2: one to detach and one to map the network.
- 22:33Speaker 1: Got it pictured in your head? You type Docker container
- 22:36Speaker 1: run dashy D dash P eighty and eighty to eighty
- 22:38Speaker 1: days eater. Try building that mental muscle the next time
- 22:40Speaker 1: you sep a project. You now have the command line
- 22:43Speaker 1: superpowers to build, run, and debug unbreakable environments. Keep experimenting
- 22:47Speaker 1: and keep building