Check out a free preview of the full Complete Intro to Containers, v2 course
The "Docker Compose" 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 introduces Docker Compose, a tool for defining and running multi-container applications. It's ideal for more local or production environments requiring orchestration between several containers. A tool like Kubernetes may be better if a project scales beyond more than a few containers.
Transcript from the "Docker Compose" Lesson
[00:00:00]
>> Brian Holt: So we talked about how to like kind of connect all these things together manually, which again, I don't really do. I learned how to do a bunch of this like networking stuff, mostly for this class, right? You basically never have to do it, just like you don't really need to create containers by hand, because there's tools that just do it for you much more simply.
[00:00:19]
So I'm gonna show you two of them. We're gonna talk about Docker Compose, and we're gonna talk about Kubernetes, and then I'm gonna add this project here called kompose, with a K that takes Docker Kompose files and makes them into Kubernetes files. Let's talk about just briefly the difference of use cases here Docker Compose is for, I'm gonna say one it's perfect for just local use cases where you're I need to spin up five containers.
[00:00:48]
I need them to network over this way. And this is how I'm going to do all my development. Docker compose is like a plus definitely use Docker Compose, that's what it's built for. They used to say don't use Docker Compose in production and they've kind of ruled that back now.
[00:01:04]
He's like, if you have a simple use case with like five containers and like that's it, or five container types, right? Docker Compose can handle that kind of traffic in production. Anything that's any more complicated than that, or you have things like scale to zero, or you wanna use things like Native where there's you have like functions and stuff like that, running into your cluster, you're into Kubernetes territory at that point.
[00:01:29]
I don't use Kubernetes locally, I don't build Kubernetes projects myself, for the most part, just as a developer, right? At that point, I probably need Kubernetes experts help because Kubernetes is both amazing and it's a pretty complicated beast to run well. I'm not gonna say it's overly complicated.
[00:01:49]
It's as complicated as it needs to be to handle the use cases that it has. So, it's a fantastic project. Okay, so let's pop into Docker Compose here. I love it, I'm a massive Docker Compose fan. I have been since they first released it. So, basically everything that we were doing that we were kind of composing things by hand using the CLI, it's just gonna end up in a configuration file.
[00:02:17]
And what's nice about that is that's more of our cattle mentality, right? Where we're able to just like add this to a Git repo and source control it, and we can just say docker-compose up and do everything we need to do and then tear it all down once we're done at the end, which I think is cool.
[00:02:36]
>> Brian Holt: So, one thing, watch out for this dash here. If you see docker-compose, that is V1 of Docker Compose. If you see a docker space compose, that's V2. I know that confused me for a long time is like, why does it sometimes have a dash and what it is it sometimes not?
[00:02:56]
That's why. Docker Compose used to be its own binary and now composed is a top level item inside of the docker CLI. Functionally for most things that you and I are gonna be doing, they're almost the same. But if you do see like stack overflow answers that have the dash in them, just know that you're looking at a V1 answer and it might be slightly different.
[00:03:21]
So do note that Docker compose is suitable for production. If you have a single instance running multiple containers, if you have anything more than that, Kubernetes is probably where you wanna go, or swarm, or Mesos, or any of the other ones. Kubernetes is just the most popular one.
[00:03:38]
Docker compose is also super useful on CI/CD scenarios, right? So if you need to stand up a mini cluster to run a bunch of integration tests or something like that, Docker Compose is great for that as well.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops