Overview
Docker is a container management system that virtualizes application environments, allowing for higher density server usage without the need for additional hardware virtualization.
Intro
Docker is an incredible and flexible tool that will likely benefit any server infrastructure. In this course we learn what Docker is, what it does, and how we can take advantage of its features!
Knowledge Check
Docker will have the ability to completely isolate applications from each other. True or false?
Containers vs Virtual Machines
Docker containers are a form of virtualization, but they're different than the traditional virtual machine concept. In this Nugget, we learn the differences, along with the advantages and disadvantages of both.
Knowledge Check
A Container deployment requires a Hypervisor just like a Virtualized Hardware deployment. True or false?
Knowledge Check
Containers offer which of the following benefits over Virtualized Hardware? (Choose two)
Knowledge Check
Docker containers are very comparable to Linux "Jails". True or false?
How Docker Works
Conceptually, Docker containers are great. In this Nugget, we learn what Docker actually does, and how it creates, manages, and maintains images and containers.
Knowledge Check
Before a Container can be built, the Dockerfile must be:
Knowledge Check
The Docker community source for pre-built Images is known as the ______ Hub.
This interactive assessment is available in the full learning experience.
Docker Installer (Deconstructed!)
Docker runs on Windows, OSX, and Linux. It's most common implementation is on Linux, and in this Nugget, we learn to install it. Because Docker containers aren't dependent on a specific host operating system, you can use whatever distribution you like (for the most part)!
Knowledge Check
Which of the following methods should be used to get the most up-to-date version of Docker?
Knowledge Check
The command to verify the version of Docker installed is ____________ version?
This interactive assessment is available in the full learning experience.
Create a Simple Dockerized App
The easiest way to start with Docker is to download a pre-made image from the Docker Hub. Using the community-driven repository enables you to get common apps downloaded and running in minutes.
Knowledge Check
Docker is limited to running in the same Linux distribution environment that your host machine is running in. True or false?
Knowledge Check
You can reference your containers via which of the following? (Choose two)
Knowledge Check
You can view the output of your container by using the Docker _____.
This interactive assessment is available in the full learning experience.
Managing Containers and Images
Once you start creating Dockerized applications, it's easy to fill your system with old images, stopped containers, and a plethora of outdated versions of your application sitting around on your system. In this Nugget, we learn to identify how images and containers should be treated, and the commands to manage them.
Knowledge Check
Which of the following describes one way in which Containers differ from Images?
Knowledge Check
You can pull images locally before creating containers from them. True or false?
Knowledge Check
To delete a local image use the command: HINT: sudo docker ________
This interactive assessment is available in the full learning experience.
Knowledge Check
Which of the following commands will list the containers on your system? (Choose two)
Networking
Most applications in a Docker environment need to have network connectivity. In this Nugget, we learn how Docker handles the IP addressing for containers and how we can access them from the local network.
Knowledge Check
Docker Containers piggy-back onto the host's default (eth0) network interface. True or false?
Knowledge Check
Which of the following commands would you use to learn the Container's assigned IP address?
Knowledge Check
You should use the Virtual Bridge Network IP Address to access a website in a Docker Container. True or false?
Advanced Networking
Docker's default bridged networking is robust and elegant, but does have a few shortcomings. In this Nugget, we learn to map ports to the host IP address, and also how to circumvent the entire bridged networking system to share the host IP with our containers.
Knowledge Check
The default Docker network setup allows computers on the host network to communicate directly with the docker container. True or false?
Knowledge Check
Expose or "Publish" a port in the container to the host network with this switch:
Knowledge Check
If needed, you can specify the port on the host network to forward to your Docker Container port. True or false?
Knowledge Check
The command to expose your container directly on the host IP address is _____.
This interactive assessment is available in the full learning experience.
Shared and Persistent Data
Docker containers are designed to be ephemeral, so it's not ideal to store important data inside the running instance. In this Nugget, we learn to mount external volumes from the host system, so that our data is stored safely outside the running containers.
Knowledge Check
It's generally considered best practice to store your data locally in a Docker Container so it can be transferred as your Container moves. True or false?
Knowledge Check
Which of the following commands would you use to mount a local directory in a Container?
Knowledge Check
If you modify a file in the local system that's mounted to a Container, those changes will be automatically visible to the Container. True or false?
Modifying Containers and Images
Occasionally, an image is almost exactly what we need, but not quite. It's possible to connect to a container, make internal changes, and then save that container as an image. In this Nugget, we learn the nuances of working with custom images created on the fly.
Knowledge Check
You have to use the random Container name that Docker provides when you run an Image. True or false?
Knowledge Check
Which of the following commands can be used to connect, or attach, to a running Container? (Choose two)
Knowledge Check
The command to save a customized Container to a new Image is _____.
This interactive assessment is available in the full learning experience.
Creating Images from Scratch
In this Nugget, we learn to create our own custom image, but rather than basing it off an existing image, we start from scratch with a Dockerfile. Building images from scratch is a perfect way to make sure you have only what components you want in your running containers.
Knowledge Check
Which of the following is the "recipe" used to describe a Docker image?
Knowledge Check
You include the FROM command at the top of a Dockerfile to specify a Base Image
Knowledge Check
Which of the following commands would you use in your Dockerfile to specify any commands to execute when the Image becomes a Container?
Knowledge Check
Which of the following commands can be used in your Dockerfile to include an external file? (Choose two)
Containers Working Together
In this Nugget, we combine the skills we've learned throughout the course to create containers that work together in order to provide a complete service. We also learn to use "data only containers," which makes shared storage portable.
Knowledge Check
Which of the following is an advantage to use a Data Volume Container?
Knowledge Check
The command to mount the Data Volume Container in a new running Container is:
Knowledge Check
Your Data Volume Container needs to be running in order to be used from other Containers. True or false?
GUI Tools for Docker
We've learned to do all the heavy lifting with Docker on the command line, but there are some GUI options available as well. One in particular enables Windows and OSX users to take advantage of Docker!
Knowledge Check
DockerUI is stored in, and accessible as, a public Image on the Docker Hub. True or false?
Knowledge Check
This element of DockerUI provides charting and graphing of all of your Docker Containers and Images:
Knowledge Check
Which of the following does Shawn recommend if you'd prefer to use a GUI interface? (Choose two)
Conclusion
I hope this has been informative for you and I would like to thank you for consuming.
View Transcript
Intro
0:00I am so glad you decided to start this Docker course.
0:03My name is Shawn Powers.
0:04I'm the guy in the picture right there
0:06with the cool little beak.
0:07No, of course not, but that's me in the picture.
0:09And I don't know about you, but I've
0:10been hearing about Docker so much,
0:12and if I'm completely honest, I didn't
0:14understand what Docker was.
0:16When somebody would say, oh, isn't Docker awesome?
0:19I would usually fluff it off with a joke.
0:21I would say something like, yeah, it's really great.
0:23I'm really happy to see that the Twitter fail
0:25whale got a new job after Twitter is now so stable.
0:29It doesn't have a job anymore being the Twitter fail whale,
0:31so now it's over here and it's the Docker mascot or whatever.
0:36And then, ha, ha, ha, everybody would laugh
0:38and then we'd go away, and I wouldn't
0:39have to talk about Docker.
0:41I didn't know, and maybe you're in that situation as well.
0:43Maybe it's around a water cooler you're standing and talking
0:46about all sorts of nerdy things that people talk about.
0:49And then the topic of Docker comes up
0:51and somebody's like, oh, man.
0:52Docker has just saved my life.
0:54I virtualized the data container and now
0:57my two subsequent containers are communicating
0:59with that in a virtual volume.
1:01It's so great!
1:02And your eyes start to glaze over
1:05and you slowly start to step away from the people.
1:08And they're like, hey, Sean, what about you, man?
1:11Don't you love Docker's ability to just completely isolate
1:14applications from each other.
1:16And I'm like, oh, yeah, it's awesome.
1:17In fact, I got to go Dockerize some stuff right now,
1:20and turn around and run away.
1:23If that's you, or if maybe you just
1:25want to learn more about how Docker
1:27works on the command line.
1:28You want to be able to utilize it.
1:30You know what it is, but you don't know how to use it.
1:32This course is for you.
1:34We're going to dig into Docker.
1:35We're going to use it, set up applications, create
1:37our own applications, Dockerize those applications.
1:40Learn all those fun buzzwords so that you can sound really nerdy
1:44at the water cooler.
1:45And at the end, you're going to understand
1:47what Docker, know why Docker is important,
1:50and why you should be utilizing it in your environment.
1:53I hope this has been informative for you,
1:55and I'd like to thank you for viewing.
Containers vs Virtual Machines
0:00In this Docker Nugget we're going
0:01to learn the difference between containers
0:04and virtual machines.
0:06Because they're very, very different
0:07although they kind of do the same thing-- one,
0:11like I said, in a little bit different way than the other.
0:13We're going to learn about virtualized hardware, which
0:15is what we're probably most familiar with.
0:17It's been around for a long time.
0:18And then I'm going to introduce the ideas of instead
0:21of a virtualized hardware, we're going
0:22to just have a virtualized environment which leads
0:26to great, great efficiency.
0:28And that's really what Docker provides:
0:30speed and efficiency over traditional virtualized
0:33hardware.
0:34So basically what is it, what's the difference?
0:36If you have virtualized hardware and you have Docker containers,
0:40what's the difference?
0:41What do they look like in practice?
0:43I've drawn out two different systems.
0:45So this outside black box here, this
0:48represents like the bare hardware,
0:50like the hard cold metal, what it means to be a server.
0:53Or I guess it could be a cloud, but that kind of ruins
0:56my whole bare metal example.
0:59Just imagine here that we're talking
1:00about a traditional virtualization
1:03system versus a traditional server running containers.
1:06So outside we have this outside layer,
1:09and this is the hardware.
1:10Inside there we have to have this blue layer, which
1:12is the operating system.
1:13So this is going to be like your Linux operating system.
1:16Or if you're doing like a one stop shop
1:19virtualization-only system like VMware,
1:22this operating system could be ESX or ESXi,
1:26and this is running on the system.
1:29On top of that is a software program or process or processes
1:33called the hypervisor.
1:35And what the hypervisor does is make
1:37teeny tiny little fake metal boxes, if you will.
1:40So notice there's black boxes inside of here.
1:44And what the hypervisor does, is it
1:45creates a virtualized hardware environment.
1:49So inside each one of these virtualized hardware
1:52environments, you have to have another operating system just
1:56like on the main system itself.
1:57So there's an operating system running inside
2:00of a computer that's running an operating system.
2:02But the hypervisor kind of carves up the resources
2:05into all of these pretend servers.
2:07As far as the operating system here knows,
2:10this is bare metal that it's installed on,
2:13because that's what it sees.
2:14It sees a complete set of hardware.
2:16And then you can run your applications
2:18inside that virtualized environment,
2:21that virtualized hardware environment,
2:23and run it separate from every other app that's
2:25running on this big machine all together.
2:29Now how containers work.
2:30They conceptually work the same, in that the applications
2:35run separately from each other.
2:38So over here they do this by creating virtual hardware
2:41machines.
2:42Over here they do it by creating containers.
2:45And it's a little bit more difficult to explain,
2:47but it's not that bad.
2:48You start out the same.
2:49You have this box, this metal box hardware,
2:52running an operating system.
2:54Now this operating system is going to be like Linux.
2:57There's not like an operating system like ESXi.
3:00This is just an operating system like Linux, Ubuntu, or CentOS,
3:03or whatever your favorite Linux operating system.
3:05Or actually it can run in Windows and OS X, too,
3:08but more about that later.
3:09But this is your underlying operating system.
3:11And inside of there it creates these tiny little isolated
3:15containers.
3:16They're called containers, and they're
3:18isolated away from the other parts of the computer.
3:21So while it doesn't create an actual virtual hardware
3:25where you have to install an operating system,
3:28it kind of separates these apps so
3:30that they don't see each other.
3:32They're in their own little world.
3:34Kind of like if you ever saw the movie The Matrix, you know,
3:36where all the people are kind of plugged
3:38into this big horrible machine that sucks their energy out.
3:42Well they're all in there, but they don't really
3:44see each other.
3:45As far as they know, they're alone in there.
3:47And maybe my Matrix example kind runs out
3:50because they don't know that they're
3:51in the horrible machine all.
3:54Nonetheless, they're isolated from each other.
3:56And while you don't have to have a complete operating
3:59system in each one of these little containers,
4:02you do have to have dependencies.
4:04So I kind of drew a little tiny blue line
4:07because you have your application and all
4:08of the dependencies.
4:10So what do I mean by dependencies?
4:11Well, let's say this is a web application.
4:14Well, this web application is going to need like PHP.
4:18Let's say PHP 5.
4:19So you're going to put PHP 5 into this thin little bunch
4:23of dependencies and anything that it needs like that.
4:26Now the nice thing is since they're separated,
4:29let's say this app here needs PHP 4.
4:32Well, that's not a problem.
4:33Because this little bunch of dependencies
4:36can be added to just this tiny little container,
4:39this tiny little isolated environment.
4:41And all of the dependencies that app needs are there.
4:43Now they don't run on a separate OS
4:47like they do over here in the virtual machines.
4:49They're all running on this single operating system.
4:52So there's nothing to boot up to run this app.
4:56You're just running the app in an isolated way.
4:59The operating system it functions on
5:01is the same for every app.
5:03Like every app knows that it's running on Ubuntu,
5:05and it's running on this same Ubuntu.
5:07But it doesn't see anything else.
5:10Everything else is isolated and separated.
5:13If that's confusing, just realize the advantages
5:16of doing this.
5:17One, it's very efficient because we've
5:19eliminated this virtualized hardware
5:22and the virtualized operating system.
5:24We've eliminated all that.
5:26There's less OS maintenance because you only
5:29have one operating system to keep updated
5:32and secured and patched and firewalls
5:34and all that sort of stuff.
5:35Whereas over here you have not only the host operating system
5:39like ESX, but you also have this operating system
5:42and this operating system and this operating system,
5:45and you have to keep them all updated.
5:47The other advantage is fast deployment.
5:49When you run one of these apps over here
5:51in the virtual machine, you have to boot up the virtual machine,
5:54wait for it to do all of the things
5:56that a computer does when it boots up,
5:57and then launch the app.
5:59Over in this environment, the computer is already running.
6:02The operating system is going.
6:04All you need to do is start the app.
6:06I mean, literally it's just like, OK,
6:08I'm going to start an app like you would start any other app.
6:11Except with containers, they're completely
6:13contained in their own little world,
6:16in their own little environment.
6:17Now there are some advantages to the traditional virtual
6:20machines, as well.
6:21You can mix operating systems.
6:22Here I could have Linux installed here,
6:25Windows installed here.
6:26If I hack things right, I could install OS X over here,
6:29and they can all be running on the same host operating system
6:33because it creates a hardware virtualization.
6:36You have to install an operating system,
6:38so it can be any operating system.
6:40Whereas over here there's only the single operating system.
6:43So everything has to be designed for that platform.
6:46So while you can use containers in Windows and OS X and Linux,
6:49all of the applications on a single device
6:52have to be running on the underlying operating system.
6:55So that is a limitation.
6:57It's more flexible.
6:58And what do I mean by that?
7:00Well, I mean with virtual machines
7:01because-- the next bullet point here
7:03that they're so mature-- because of that maturity,
7:05you can like migrate live running machines over
7:09to another host machine.
7:12And you can do live migrations.
7:14You can do failover stuff.
7:15The whole world of containers and Docker and all that stuff
7:19isn't quite that developed, that mature, and that robust yet.
7:22If you have an app running here, you
7:24can migrate it to another server,
7:26but it's not like a "hot" moving like it
7:28would be with one of these virtual machines.
7:32Now I think we're going to see more and more and more
7:34of that stuff as we continue to abstract the idea of what
7:38the operating system is, but I'm getting
7:40a little philosophical right now.
7:42So for the point of Docker, you have
7:44to know that it's not quite as mature or as flexible
7:47as virtual machines, but the advantages
7:50make it so awesome and so worth it.
7:53One last little tidbit that I want
7:54to mention because I get this question a lot
7:56from Linux users.
7:57Like if you're a Linux user, you're probably thinking,
8:00isn't that just the same as a jail, where you log in,
8:03and you're isolated, and you can only see whatever
8:06your jailed environment is?
8:08Well, how a jail works is, let's say
8:10I have an FTP running on this server.
8:12So this is a representation of the file system on a server.
8:16So if I have an FTP server running,
8:18when I log in-- if we have the FTP server set up
8:21in a jailed environment-- when I log in,
8:24the only thing I'm going to be able to see
8:26is my personal folder.
8:28So if I were to type something like ls -l /,
8:32it's going to give me the directory contents of spowers,
8:34because that becomes my root directory when
8:38I'm jailed into spowers.
8:40So really what this does, it's a little bit
8:43like Docker in concept, but only when it comes
8:46to the file system itself.
8:48Everything else of the rest of the system--
8:51all of the dependencies like PHP and everything--
8:53it's all going to be the same version.
8:56The only thing that jail does is isolate
8:58the user who's logged in from seeing
9:01any other files on the system.
9:03So it's like a teeny tiny baby version of a container,
9:07and it's obviously a security thing.
9:09We don't want people who are logging in via FTP as spowers
9:12to be able to see tsmith stuff or stuff in the boot directory
9:16or anything like that.
9:17So that's what a jail is.
9:18It is like one step towards the idea of containers,
9:21but it's not all the way.
9:22It just restricts users from seeing other files
9:26on the system.
9:27If your interest is piqued, I'm excited.
9:29Because it's a really awesome technology to learn when
9:32it comes to containers versus virtual machines.
9:35Unfortunately, the world of containers
9:37is kind of confusing at first.
9:39So I want to dispel all of that and reassure you
9:42that it's not complicated.
9:43It's just really cool and a new way of thinking.
9:46I hope this has been informative for you,
9:48and I'd like to thank you for viewing.
How Docker Works
0:00Well, it's great to understand how Docker works.
0:02It's important to know that Docker, itself, is not
0:05the technology that allows us to do things like use containers.
0:09So in this Nugget, we're going to learn
0:10exactly what Docker's role is in this whole containerized
0:15version of applications.
0:17We're going to learn about what Docker files are, what they do,
0:20images, and then containers, which
0:22are kind of, like, buzz words in the Docker world.
0:24But they'll make sense because it's
0:25kind of like three different stages to utilizing the Docker
0:30technology in order to best use containers,
0:33which again, like we've learned before,
0:34is a way to isolate applications so that they can work,
0:38regardless of the kind of a server they're hosted on.
0:41Now, before we talk about how Docker itself works
0:43and what its role is, let's talk about the three
0:46different steps, or stages, for containers
0:50working in a Dockerized system.
0:52First, we start with a Docker file.
0:54And it's called Docker file.
0:55And it's basically like a recipe for how
0:58to create an environment that the application is
1:01going to run in.
1:02So, you know, you have things in the Docker file
1:04like dependencies that are needed, like I need PHP,
1:07I need EngineX installed, and I'm
1:09going to need a Java environment.
1:11And we're going to do that on top of all of the,
1:14oh, let's say, Debian system dependencies.
1:16Now, again, it doesn't mean that the host
1:18has to be running Debian.
1:19It's just saying, in this particular container, that's
1:22the system that we need.
1:23These are all the dependencies and applications
1:26that we need in order to have our container work.
1:28And then this Docker file is then compiled into an image.
1:34Now, an image is not something that is run directly.
1:37Think of an image as kind of like an ISO file for installing
1:40an operating system-- everything you need to run is in there
1:44but you don't usually run it off the CD,
1:46not unless it's a bootable CD, but just
1:48pretend those don't exist.
1:50Images don't actually run the application.
1:52It just contains everything that is
1:55specified in the Docker file.
1:58So you follow the Docker file, which is like a recipe,
2:00and this is what you get.
2:02This is your end result. This is the baked cake
2:04that is everything you need in order to function, OK?
2:07From this image, we make containers.
2:11And basically, what it does is it clones this.
2:13So it makes a copy of everything in the image
2:16and it turns it into a container, which
2:19is what actually executes.
2:20So the image is just like a baked cake
2:24that we take slices off of to make containers.
2:26Now, the cake and slices thing doesn't work well
2:28because it's actually-- containers
2:30are an exact copy of the entire image.
2:33So it's not like we really take pieces off of it.
2:36It's actually a complete copy of the image.
2:38But we make a copy and that's what actually executes.
2:42So we can make multiple copies of the image,
2:46the same exact image, and we can have containers
2:49that do the same thing, which really makes it
2:51scalable and kind of awesome.
2:54But these three steps are vital to understand
2:56because Docker's role is to manage every different step.
3:01So what Docker is?
3:02Docker is not the container technology.
3:04Docker is the arrows in my illustration here, right?
3:07Docker does everything in here.
3:09It, actually, is the tool we use to create
3:12an image from a Docker file.
3:14Docker, you know, our cool little whale guy over here,
3:16he says, OK, I see your Docker file.
3:19I will create an image.
3:20And then the Docker program creates this image.
3:24And then when you want to spawn off a container,
3:27the Docker engine is running, and it says,
3:29OK, I'm going to take the image that you created from a Docker
3:32file and I'm going to clone it into a container
3:36and execute that container.
3:38So Docker, the whale, the Docker program, the daemon,
3:42however you want to think of Docker,
3:43its job is to facilitate all of these different steps.
3:47And that's what makes automation so much easier with Docker
3:51than if you're trying to create containers on your own.
3:54Because again, the Docker program
3:56is not the technology that allows containers to execute.
4:00That uses existing container technology
4:03that has existed for years.
4:05Docker is just kind of the shipyard manager
4:08here that makes all of this possible and easy and simple
4:11to replicate, simple to scale.
4:13So Docker makes a process that used
4:15to be difficult simplified, easy, and organized.
4:19You know, the whole concept of a Docker file alone is awesome.
4:22That's how we create the images.
4:24Now, one more cool thing that Docker has a built into it,
4:27is the ability to get rid of some of these steps.
4:30Because if you want to create a web server-- like here,
4:33I have things here that look like they're creating a web
4:36server-- PHP, EngineX, Java.
4:38That's the kind of thing-- we'll say that this container is
4:41a web server, OK?
4:42If you want to create that image, you can go ahead
4:46and you know, write a doctor file on your own.
4:48Or you can go online where people have already
4:52created a bunch of images.
4:55So this could be a web server-- this thing.
4:58And on your computer, whether you're in a home environment,
5:01in a school, or office environment, you say,
5:04you know what?
5:04I want to run a container that is a web server.
5:08Well, what you can do is download from Docker Hub
5:11a premade image.
5:13It's premade, it's updated by the person over here who
5:16wrote the original Docker file.
5:18They make their images public.
5:20You download an image that's somebody
5:22has made professionally, and you don't
5:24have to worry about getting all the dependencies right.
5:26This image is already all set.
5:28You download it and you execute it.
5:30So Docker is not only this daemon that
5:33allows you to manage all the steps of the containerization
5:37process-- is that a word?
5:38I don't know.
5:39But it's also a community of people
5:42that work together to make it simpler for everybody.
5:45It's truly, truly awesome.
5:47And if you're still struggling with the idea of what
5:50does it mean to containerize an application?
5:53I just don't get it.
5:54Well, I urge you to look at the Nugget
5:55we did on virtual machines versus containers.
5:58But also, if you were around when the portable apps
6:01phenomenon was really popular-- and a lot of people
6:04still use portable apps real like download a program
6:06and run off a USB drive and take it anywhere
6:08and it all the dependencies are stored
6:11on that USB drive in a folder so you
6:13don't have to install anything on your system.
6:15That's kind of what containers do,
6:17but they scale it up to a server world where everything in here
6:21is self-contained.
6:22You don't have to worry about if you have, you know,
6:25the proper versions of PHP and that sort of thing installed.
6:28This whole Docker process depends on you already
6:32understanding how containers work and why they're awesome.
6:34Because Docker just allows you to do something
6:37awesome in an easier, more efficient way.
6:41And truly, that's the goal of this Nugget.
6:43I want you to understand what Docker
6:45is and almost more importantly, what Docker isn't, right?
6:50Docker is not the technology of containerized applications.
6:54Docker is just the system that allows
6:56us to do something that's been around for a while
6:58and make it flexible, awesome, scalable, community-driven,
7:02just really, really cool.
7:04I hope this has been informative for you.
7:06And I'd like to thank you for viewing.
Docker Installer (Deconstructed!)
0:00Now I know we really just want to get in there
0:01and get Docker installed so that we can get creating and doing
0:05all sorts of Dockery things.
0:06But I want to talk a little bit about the installation process
0:09itself.
0:10Because while it's super simple, the installation process
0:13seems too simple.
0:14Like really, it's an evil whale that's
0:16trying to take over our system by letting
0:18us do some scripts that just magically happen.
0:20I don't like magic when it comes to computers.
0:22So I want to show you what not to do but I also
0:24want to show you what the installer actually
0:27does on your system.
0:28And what can make things super, super confusing
0:31is that if you do apt-cache search for docker,
0:34you're going to see that in your repositories
0:37you have Docker already there, ready to install.
0:40Here's the problem.
0:41It's a super old version and it is not updated regularly,
0:44so you're definitely going to want to get the latest
0:46version directly from Docker.
0:48Now how do we go about doing that?
0:50Thankfully, it's super simple.
0:51This is the part that's so easy it's creepy.
0:53All right, if you go to get.docker.com, which we've
0:56done in this web browser right here, and you can see
0:58there's just a couple simple instructions.
1:00What we're going to do is we're going
1:01to use curl to download the script that you actually
1:04see on this page.
1:05It's a little meta here.
1:06This is the actual script that starts here.
1:09And if you'll scroll down the whole page,
1:11you'll see the whole web page here is just one batch script.
1:14And this command will allow us to download it and save it
1:17as a file called get-docker.sh.
1:19So let's do this really quickly.
1:21So I'm just going to Paste.
1:22And if we do an ls, then we're going to say, sure enough.
1:25There is get-docker.sh.
1:27Now I'm going to change it so we can execute it.
1:29So chmod + x get-docker.sh.
1:34And now if we look over here, see it says just sh
1:37get-docker.sh.
1:38So we can do that.
1:39sh get-docker.sh and it's going to walk us through the process
1:44of actually installing the latest version of Docker right
1:48from docker.com.
1:50And that's what we want because we
1:51want to have all the latest features and the most updated
1:53version.
1:54Now the really cool thing is, while this is all automatic
1:57and I don't necessarily like executing
1:59random scripts on my computer with root access,
2:02here's the deal.
2:03This is going to not only install Docker and like put it
2:06in a binary place, it's actually going
2:08to download the repository information so that we can
2:11keep it updated using apt-get.
2:13And I'll show you where that goes
2:14as soon as it's done downloading and installing.
2:17And just like that, it's done.
2:18Now it does say that we can make some changes to our system
2:21if we want to make it so that we can run Docker as an end user.
2:24We're just going to be running Docker with root privileges,
2:26but you can do this if you want to set up a system that's
2:28going to be permanently using and you
2:30got to make sure that it's as secure as possible.
2:32But Docker is installed.
2:34If we go over to the etc/apt folder
2:37and go into sources.list.d, we can see
2:40it's created an app list file.
2:43And if we look at that, we can see so now
2:45it's going to download the latest
2:47stuff when we do something simple like apt-get update.
2:50And when we do an apt-get update,
2:52it's going to pull information from the Docker site as well,
2:55not just one that is in our existing Ubuntu repository,
2:59because again that one is really, really old.
3:01And you can tell we have the new version
3:03because if we type docker version, boom,
3:05it's going to show us.
3:06We have Version 18.06 here.
3:08And it's OK if this isn't the version you have.
3:10The point is, we want to make sure that we're
3:12using the sources list from Docker
3:15so that we get the very latest version from docker.com.
3:19I hope this has been informative for you
3:20and I'd like to thank you for viewing.
Create a Simple Dockerized App
0:00It's great to understand conceptually how Docker works
0:03and how containers work in a system.
0:05But for me, until I actually see it in action,
0:07it just doesn't make a whole lot of sense.
0:09So in this Nugget, we're going to create a simple Dockerized
0:12app and actually run it in the real Docker environment.
0:15Now, it's going to do a couple things.
0:16We're actually going to get to look at Docker Hub, which
0:19is an online repository for pre-built images
0:22that we don't have to build from scratch, we can download.
0:25We're going to learn what images actually are, how they work,
0:27and where they're storing all that sort of stuff.
0:29And then we're going to see how logs work,
0:32because when we do a Dockerized app, if we want
0:34to see what it's doing, we need to look at the logs,
0:36because it kind of just goes in the background
0:38and runs as its own background application.
0:41So let's just do it.
0:42Let's just create an app, put it in the Docker environment,
0:45and see how it goes.
0:46And then we'll explain and learn about what
0:48it does along the way.
0:49So first of all, what apps are we going to Dockerize?
0:52Well, I like simplicity, so we're
0:54going to do a very simple app.
0:55Let's see it right now.
0:57Now, we could use any application and Dockerize it.
0:59Usually, people use Apache, because it's
1:01easy to see the end result, or a web page is being served.
1:04But I want to do something even simpler,
1:06so that we're focusing on the process rather
1:08than the application itself.
1:10So let's say bash.
1:11It's going to be a little bash script.
1:12So we do bash - c.
1:15And then we put the script in single quotes here.
1:18It's actually going to run it.
1:19So let's do a while loop-- while true, do X=, X, sleep 1, done,
1:32in single quotes.
1:33Now if this looks a little bit confusing, in other courses
1:36we've actually covered bash scripting.
1:38You don't really have to know all of the intricacies
1:40of what's going on here.
1:41Basically when I hit Enter, this is what's going to happen,
1:43it's going to say one, two, three, four,
1:45and it's going to count to all of infinity.
1:47And that is our whole application, right?
1:49That's all that we're going to Dockerize,
1:51is a computer counting.
1:53I know it's kind of lame but there's not much
1:55that can go wrong with it.
1:56So when we Dockerize it, what we do is,
1:59we have to use a Docker app.
2:00So we're going to say, sudo docker, and we're going to say,
2:05Run.
2:05Now, Run will do a couple things.
2:07Run is going to execute the command we tell it to,
2:09in whatever environment we tell it to.
2:11But the cool part is that it will look in our local image
2:15repository for an environment to run our application in,
2:18and if it doesn't exist, it will download it from Docker Hub.
2:21So we're going to say, docker run.
2:23I'm going to say, -d, so that goes in daemon mode
2:25and runs in the background.
2:27And the first thing we say is, what environment
2:29do we want it to run in?
2:30Now, the computer that we're on right here,
2:33this is actually Ubuntu.
2:34So just to mix things up, let's say
2:35we're going to run it in the CentOS environment,
2:38or on a CentOS image that is downloaded from Docker Hub.
2:42And then we simply say, OK, so what is it
2:44that we want to run in that image, or in that container
2:48that we create from the CentOS image?
2:50And that's where we say, /bin/bash.
2:51Actually, let's just copy and paste this whole thing,
2:54because that was kind of a pain to write.
2:57So we will copy and we'll paste all of that.
3:03So to do that, we hit Enter.
3:05It asks for a password, because it's sudo,
3:07and we have to have root access to run Docker.
3:09Press Enter.
3:09It says, hey, look man.
3:11I can't find that image called CentOS.
3:13I don't have an image like that.
3:14So what it does, it goes on the internet,
3:17and it will download the CentOS image for us from Docker Hub.
3:21See, it goes through.
3:22It's going to download it.
3:23It will take a little bit.
3:24I'll probably fast forward here.
3:25But it's going to download the entire CentOS environment.
3:28Notice it's not a CentOS virtual machine,
3:30it's just all over the dependencies and stuff that is
3:33required inside of a container.
3:35So I actually don't even have to fast forward,
3:37because we're already done.
3:38Boom.
3:38OK, so it downloads all that.
3:40It extracts it, and now we have the CentOS image locally
3:43on our computer.
3:44It uses that image to create a container,
3:47and inside that container, it runs
3:49the application we told it to.
3:50Now our application is just this simple script.
3:53So right now we have a container that is counting, one, two,
3:57three, ha, ha, ha.
3:59It's counting all the way up to infinity, right?
4:01Unfortunately, we can't see anything.
4:03We're like, um, it just gave us this really ridiculously long
4:07string that's actually the container ID number.
4:09But other than that, we have our computer back.
4:12What the heck?
4:12Well, we can type, sudo docker ps,
4:16and it's going to show us what containers
4:19are running on our system.
4:21So here, now-- it word wraps a little bit weird,
4:23so bear with me.
4:24This is the container ID.
4:26Notice this is actually the same thing up here, just kind of
4:28truncated.
4:29They do show you the first little bit of it.
4:31So this is the container ID.
4:32This is the name of the image that it's running.
4:35So this is the environment that we have.
4:37It's running in a CentOS environment,
4:39even though we're on Ubuntu.
4:40The command it's running-- it actually truncates this,
4:42but it's our bash script that we entered in, so it's counting.
4:46It was created 35 seconds ago.
4:47It's been up for 34 seconds.
4:50And then, while it word wraps weird, it says the name.
4:53And then, the name that they gave it is hungry_hopper.
4:55Now, that's bizarre.
4:56And if you're doing this at home,
4:58it's going to be different.
4:59You're going to have some random name here as well.
5:01What they do is, rather than referring to your containers
5:04by these long, ridiculously complicated,
5:07randomized strings, it will give it a name.
5:10Like, it could be hungry_hopper.
5:12It could be lovely_luminaire.
5:14It could be all sorts of things, and it's
5:17going to make it random.
5:18It's going to be, probably, silly.
5:19I've never seen one that isn't a little silly.
5:21And you can reference this container by this name
5:24that it randomly assigned it.
5:25Now, it's running as a daemon in the background,
5:28so we don't see any output, right?
5:30Well, that can be kind of a problem,
5:31because we want to see our application is running.
5:34If it was a web server, we could open up a browser
5:36and check it out.
5:37But it's not.
5:37It's just counting on the command line.
5:39So in order to see that, we need to look at the logs
5:42this is creating.
5:43Because what it does is the console output--
5:46like, of the output from our actual command--
5:48is stored in a log.
5:50So how do we do that?
5:51Well, Docker has a fancy command for looking at the logs.
5:54It's not even a very difficult command to remember.
5:56If we were to type, sudo docker logs,
6:00and then we can tell it what log we want to look at.
6:03Now the cool thing is, like I said,
6:04we have this fancy hungry_hopper nickname, so we can say,
6:07sudo docker logs hungry_hopper.
6:09Or we could take the first few characters
6:12or the entire string.
6:13Whatever you want to refer to.
6:15You just need to have a couple or the whole thing.
6:17We can actually just say like, sudo docker logs fd5c44,
6:23and that's probably enough.
6:25Hit Enter, and it's going to show us what it's
6:27been doing in the background.
6:28Now it just gave us a snapshot log, right?
6:30It counted up to 197 in the time that we
6:33were sitting here talking.
6:34So if we go back and type, ps, again-- OK,
6:37hungry_hopper is there.
6:38What if we were to type, sudo docker logs hungry_hopper.
6:44It's the same thing that it referenced,
6:46and in the time between when we type the container
6:48ID and hungry_hopper, it actually counted from 197
6:51all the way up to 218.
6:52So it's running in the background, right?
6:55Type, ps, again.
6:56So we can see, this is still running in the background.
6:58It's been up for three minutes, and to be honest,
7:00that's all there is to running a containerized app.
7:02We could log out of the system, we could go home,
7:04reconnect with Docker, and it would
7:06be counting for all of infinity in the background.
7:09Now, if we want to stop it, we can simply type, sudo docker
7:13stop hungry_hopper, and it's going to stop hungry_hopper,
7:19meaning this container that is executing--
7:21or this application that's running
7:22in this container-- it's going to stop the entire container.
7:25And all it will give us is the name hungry_hopper.
7:28and basically it's saying, OK, it's stopped.
7:30And if we want to see, type, docker ps, again.
7:33Nothing is running in the background.
7:35If we were to type the logs for hungry_hopper,
7:37we would see it counted to 279.
7:40If we do it again, it's not running, right?
7:42If I do this over and over, it's just
7:44going to only show us 279 because it stopped.
7:46It's no longer counting.
7:48And that is how you interact or see what the process is doing.
7:52We've stopped it.
7:52We could also start it.
7:53Sudo docker start hungry_hopper.
7:59So it started hungry_hopper.
8:00Now, if we look at the log file again, look, it started over.
8:05And it's now up to six.
8:07So it stopped right here, we restarted it,
8:09and it started at x equals 1.
8:10So one, two, three, four, five, six, boom.
8:12It's working, it started again.
8:13So we can start it, stop it at will.
8:17Now if we look at the log files, we counted up to 30.
8:20If we look again, it is still at 30 because it stopped.
8:23Sudo docker ps.
8:25It's going to show us nothing is running.
8:28Now, don't worry.
8:29If you want to learn more about Doctor Hub and images
8:31and stuff, we're going to look at other stuff like that later.
8:34I just wanted you to be able to say, hey,
8:36I have run a Dockerized app.
8:38I am a Docker god.
8:40You can say that if you want, and as long as nobody
8:42quizzes you about your intimate knowledge of Docker, hey,
8:44you're in good shape.
8:45But truly, we really did Dockerize an app
8:48and run it and have it be executed in a Docker system.
8:51At the basic level that's all Docker
8:53is doing is running this environment in the background.
8:56And we did.
8:56We ran that application in the background, so, success.
8:59If all you wanted to know is how to Dockerize a simple app,
9:03you can stop watching this course,
9:04because you are now as educated as you want.
9:06I do encourage you to keep going,
9:08because it's going to get even more awesome as we go on.
9:11I hope this has been informative for you
9:12and I'd like to thank you for viewing.
Managing Containers and Images
0:00Hello, everybody.
0:01In this Nugget, we are going to learn
0:02to manage the images in containers on our Docker
0:05system.
0:06Now we're going to learn how to update and delete those images.
0:09We're going to learn how to start, and stop, and remove
0:11containers, because one of the problems with Docker
0:13is that it's so darn easy to do stuff, sometimes
0:17you end up with containers that just pile up
0:20and kind of make a mess of your system.
0:22Now, it doesn't do much more than use up storage space,
0:25but it really can get confusing if you
0:27have like 13 different versions of a container
0:30and you're not clear which one you want to start,
0:32which one you want to--
0:33so today is like how to clean up.
0:34We're going to clean up.
0:35Clean up.
0:36Everybody do their part.
0:37And we're going to learn how to make
0:38our system efficient by dealing with the images and containers.
0:42But first of all, we need to learn exactly what
0:44images and containers are.
0:46I mean, we already know what they are, but how they differ,
0:48and how we should think about them,
0:50so when we manage them, clean them up, keep them updated,
0:53we do it in a way that makes the most sense
0:55and is the most efficient and helpful.
0:57Now like with most things in life,
0:58I like to think of the images and containers
1:02in silly little ways that just make sense to me.
1:04So I like to think of images and containers
1:08as like the image pasture in the container arena.
1:10And what I mean by this is here in the pasture,
1:13we have things like images that will host Java applications,
1:17or images that will host PHP applications,
1:20usually contain Apache.
1:21Often, Apache and PHP are installed together.
1:24And these images are kind of like a pure version
1:27of the environment that's required
1:30to run those applications.
1:32What we do is we take a copy of these images
1:37and we kind of put them into the arena with the application
1:41on top of it.
1:41So these are the environments that we have.
1:44The images are the environments.
1:45And then, once they are containered, or containerized,
1:49or copied over and put into live action,
1:51they are live apps where they battle each other to the death.
1:54No, where things happen to them, right?
1:56This is where the application is actually running,
1:59getting accessed by the outside back and forth.
2:01If you're on your computer here, you're
2:04going to be accessing the applications that are running.
2:07These get messy, right?
2:08These can get big long log files, errors.
2:12If something's going to go wrong,
2:14it's going to happen in this container arena.
2:17It's not going to happen in the image pasture
2:19because images don't directly get influenced or connected
2:23to by the outside world.
2:25They don't actually do anything except sit here in the cozy pen
2:29and wait to be copied off into the container arena.
2:32So what that means is that if we are
2:35going to update a container or an application,
2:39we actually just get rid of it.
2:41We just, boom, get rid of the application,
2:44start with a fresh copy of this image,
2:48and then add any changes to the application.
2:50So generally, you think of the applications and the containers
2:53that are inside our container arena
2:56here, inside our container spot on our system, as expendable.
3:01These are the applications that you've prepared
3:04and you've sent off to war, but when it comes time
3:07to updating or making significant changes,
3:11you want to do that at the image stage
3:13or at the deployment stage so that your images stay pure
3:17and you're not just building on top of something that's
3:20been running.
3:21So these are expendable.
3:23We want to get rid of all the containers
3:25that aren't being used and start from scratch
3:28by creating a new container from our pristine images,
3:31if possible.
3:32So again, containers-- expendable, images--
3:35fresh, pure.
3:36That's where we want to start from.
3:38So on the system, they're not chickens, and ducks,
3:40and horses, and pigs, they're actually environments.
3:43Like I said, Java environments, Apache environments, et cetera.
3:46And then when we deploy them, they
3:47have apps built on top of them.
3:49Now I should say, sometimes, the actual images
3:53will have the app built-in, but the same process still happens.
3:57If there's an update to the app, we actually
3:58make the update here and then deploy it.
4:00We never update the one that's actually running.
4:03That's just not how we do things.
4:05So let's go to our system and see
4:07how we keep our images updated and our container area cleaned
4:10up.
4:11Now some of this might be review,
4:12but to see the various images that are pulled onto our system
4:16and exist in our image pasture, so to speak,
4:19we type sudo docker images, and it will show us all those
4:23that we've downloaded.
4:24So here you see I have the CentOS latest image.
4:28We could do some more.
4:29We can actually pull--
4:30now when we created a Docker containerized app before,
4:33it actually downloaded the base image for us
4:37automatically during the run process.
4:39But we can actually pull an image and have it local.
4:42Anyway, we could say sudo docker--
4:45let's search for PHP.
4:48So we'll search for PHP.
4:49This actually looks on Docker Hub.
4:51And I know there's a whole bunch of them here,
4:53but what I like to do is scroll to the top
4:55because the most popular ones are always at the top.
4:57Like 278 stars means people have said,
5:00this one works really well.
5:01And it's just called PHP.
5:04So if we were to say sudo docker pull php,
5:10it's going to pull that image from the Docker Hub repository,
5:16and it's going to download it.
5:17And then I want to show you something
5:18that's actually kind of cool.
5:19It's pulling the PHP image so we can use PHP as our base image
5:24when we're creating Dockerized apps.
5:26But it also does something else that's kind of cool.
5:29See, so it's pulled and downloaded
5:31all of the information so we have the PHP image.
5:34But if we do sudo docker images, we'll
5:38see that even though there were multiple parts that it
5:40downloaded, it just downloads into this single image that
5:44contains all of the dependencies required.
5:47Now, we could also sudo docker pull ubuntu,
5:52and it will pull the Ubuntu image,
5:54if there's something you need Ubuntu for specifically.
5:57And basically, what we're doing is building up
6:00our image pasture.
6:01We're putting images in here so that we can build on them when
6:05we create application containers that will require
6:08those in order to function.
6:11So if we here go docker images again,
6:13we're going to see that it has pulled all that.
6:15Now, you may look right here and say, well, this already exists.
6:19Well, that's because these images
6:21are built on dependencies of other things.
6:23It's going to actually only download the specific parts
6:27that it needs in order to function.
6:29So these images may have dependencies on each other,
6:32but Docker does a great job of just taking
6:34care of all of that in the background.
6:36So you don't have to worry.
6:37As long as you say, I want the PHP image,
6:40it's going to download all the parts that it needs.
6:43and when we look at Docker files later on,
6:45we're going to see what it takes to build an image
6:47and we'll see that they can call dependencies
6:49of other applications that are required
6:52for the environment because for PHP to run,
6:54it needs a web server.
6:55So you can be sure that part of this 444 megabytes
6:59is a web server application.
7:01Now, we've abstracted out what that web server might be.
7:05We don't even know.
7:05What web server is it running?
7:07Is it Nginx?
7:07Is it Apache?
7:08We don't know specifically.
7:10We just know that we have the ability to serve PHP.
7:13So Docker does a nice job of abstracting out
7:16all of those underlying details of what we would need.
7:20So that's actually kind of a cool thing.
7:21But so that's images.
7:23Now, we can actually pull images.
7:25We can also delete images.
7:27So if we do sudo docker rmi php--
7:34now why rmi?
7:36Well, it's like rm, like the Linux command line
7:38rm, and i for image.
7:40So rmi is remove image PHP.
7:43Now, if we look back and see our images here,
7:45we only have Ubuntu and CentOS because we've
7:48deleted that PHP image.
7:50Now, if we started or if we run a container that requires PHP,
7:53it will automatically download it.
7:55But we can just have that there in the first place.
7:58Now, what if something here gets out of date?
8:00We could actually say sudo docker pull centos.
8:04And we already have CentOS.
8:07But if there are any updates to the CentOS image
8:11up in Docker hub, it will actually go and test and see.
8:14And here, we already have all of the updates
8:16that have been done.
8:17But that's a way we can keep our local images
8:19up-to-date, as well.
8:21So that's how we manage images.
8:22I do want to look at containers.
8:24So if you remember how to look at containers,
8:27docker ps will show us all of the running
8:30containers on our system.
8:31Just like the Linux ps command, the Docker ps command
8:34will show us all the running containers.
8:37So here we have a container called suspicious_euclid,
8:40and it is running this bash while loop.
8:43It's just a simple counter loop that we looked
8:45at in a different Nugget.
8:46And it was created 10 minutes ago.
8:47It's been running for 10 minutes.
8:49Now, that's good.
8:49We could stop it.
8:50But I want to show you another command.
8:52If we type sudo docker ps -a, it's
8:56going to show us all of the containers,
8:58whether they're running or not.
8:59And this is where you can start to get
9:01a whole big mess of containers just sitting on your system,
9:04not running but taking up space, and making it a little bit
9:06confusing.
9:07If you look here, we still have suspicious_euclid,
9:09the one that's running.
9:10And it's currently running.
9:12Its status is it's been up for 10 minutes.
9:13But we also have hungry_hopper, which was
9:15created in a different Nugget.
9:17And this is the same command, actually,
9:19but you'll see here it exited five weeks ago.
9:22So it's exited, it's not currently running,
9:26and it doesn't show up when we simply type ps.
9:28So up here, we typed ps.
9:30We didn't see hungry_hopper show up at all.
9:32But when we type ps -a, it shows us all of the containers,
9:35running or not.
9:36And so if we want to get rid of one--
9:38sudo docker rm hungry_hopper--
9:43so notice now it's not rmi.
9:45It's not an image we're trying to remove,
9:46just rm because it's that container
9:48that we're trying to remove.
9:49So now if we type ps -a, we'll see that suspicious_euclid
9:52is there.
9:53Now, if we tried to do that, if we try to delete that,
9:58we have a problem.
9:58It says, whoa.
9:59You can't do that.
10:00It's actually still running.
10:01Now, if we wanted to remove it, we could say -f
10:05and it would actually stop it and remove.
10:08But that's just a safety feature so you don't accidentally,
10:11while you're trying to clean up your system,
10:13remove a running system or remove a running container.
10:16So we could say sudo docker stop suspicious_euclid
10:21and it's going to stop that, and then we could erase it.
10:25So now if we say rm suspicious_euclid,
10:26it's going to do that without a problem.
10:28If we go back and say ps -a, we have nothing running,
10:31but we do still have images.
10:33See that?
10:33We still have the two images, the one that we just downloaded
10:36and the one that's been in our system for a while.
10:38So really, the gist of this Nugget
10:40is to learn these few commands and understand
10:42what they're doing.
10:43ps, ps -a is to look at containers, not images.
10:47To look at the images on your system, you type images.
10:50And there is no images -a.
10:52That doesn't exist.
10:52That concept doesn't exist because images are never
10:55running or stopped.
10:57Images are always just not running.
10:59They're just the staging area.
11:01They're kind of in your pasture there,
11:02waiting to be copied and put into play.
11:04So while pa and pa -a do different things--
11:07one will show you running, one will show you all--
11:09with images, you see them all, no matter what.
11:13If you type sudo docker images, it's
11:14going to show you all the images on your system.
11:16To pull an image to your local system from Docker Hub,
11:19you use the pull command.
11:20And then to remove, you do rm to remove containers,
11:25rmi to remove images.
11:27So again, that difference is this "i." rmi
11:30is not a Linux command.
11:32You type rm to remove things on the Linux command,
11:34but rmi is something new.
11:36So just think of it as rm for images,
11:39and that's how you remove images on your system.
11:42Images are usually pretty safe to remove because you can just
11:45re-download them, unless it's a custom image
11:47and you want to rebuild it.
11:48But we'll learn about that later.
11:49But remember, the whole concept with Docker
11:52is that you want to remember, your containers
11:55are kind of the live systems.
11:57They're in place and you don't want to spend too much time
12:01tweaking them.
12:02You want them to be deployed from the image
12:05pretty much how you want them to run so that you can
12:08erase the container and spin a new one up
12:10without worrying that all of your stuff has been lost.
12:13But that's how you manage both images and containers
12:16and how you identify them on your system.
12:18It may seem like simple concepts that we went over today
12:22with images and containers, but understanding
12:24how to update them, delete them, start them, stop them, remove
12:28them, and know which one you're removing-- it's
12:29very important, especially when you
12:31start playing with Docker, which is something I urge you to do.
12:35If you just make a whole bunch of containers,
12:37it's great practice, but you need
12:38to be able to learn how to manage them and delete them
12:40so you don't just have 50 containers
12:42and you don't know which one is doing
12:43what, which one is the most recent one, et cetera,
12:45et cetera.
12:46So get in the habit of cleaning up after yourself
12:48on your Docker system, and it'll make things a lot easier
12:51as we move forward making custom images and things like that.
12:54I hope this has been informative for you
12:56and I'd like to thank you for viewing.
Networking
0:00In this Nugget, we're going to learn about docker networking.
0:02Because it's great to set up containers,
0:04and it's great to see them do things on the local computer,
0:07but in a real world situation, you're
0:09going to have to have a network connected to your application
0:13in almost 100% of the scenarios.
0:15I mean, it's possible that you're
0:17going to do a standalone app that
0:18doesn't need network activity.
0:19But gosh, that's just pretty darn rare.
0:21So we're going to learn today about how
0:23the docker system handles these virtual network interfaces.
0:27By default, it does bridged networking.
0:30I'll explain what we mean by that.
0:31And then, kind of a challenging thing that's a little bit
0:34tough to figure out at first is, how you can figure out
0:36your containers IP address.
0:38Now there are some more advanced networking things
0:40we'll do in another Nugget.
0:41But this will give you the gist of how things work by default
0:44when you open up docker and start a new container
0:47and get it going.
0:48If you've been poking around your docker host
0:51around the installation of what you've already done,
0:53you may see a few things.
0:54There is of course an eth0 on your system.
0:58All Linux systems have an eth0.
1:00Most of them do.
1:01And that is your host IP address.
1:03In my situation, it's 192.168.1.
1:06something.
1:06I guess it's like 201.
1:08It may not be that 201 is the actual IP address,
1:10but it looks something like that.
1:11When we installed the docker program,
1:13it also created a virtual interface called docker0.
1:18And that is assigned another private IP space.
1:21So this is not routable on the internet.
1:23But it gives it an IP address something like 172.16.0.1,
1:28or something usually in the 172 range.
1:32And what this is, it's a separate network,
1:34but it's an actual IP address assigned to the computer.
1:37So if you have another computer on your network
1:39that you assign an address in this range,
1:41you can ping this docker0 address on the host machine.
1:45So when you spin up, or start, a container docker
1:50runs it on the local computer.
1:51But it actually also gives it a network environment of its own
1:55too.
1:56So inside of the container, the container
1:58itself will see its own the eth0.
2:01And that will be assigned an address a lot
2:05like that docker0 address-- 172.16.
2:08something dot something-- so that it's part of that network.
2:10And here's where it gets a little bit confusing.
2:12But hopefully it'll make sense.
2:14It also, when this container starts,
2:16creates another virtual ethernet adapter on the system.
2:22And it starts with v for virtual.
2:24So veth, and then it gives it a long string
2:27of letters and numbers.
2:28It's basically matches that containers Mac address.
2:30But it doesn't matter if you know
2:32where the numbers come from.
2:33But this it creates this virtual ethernet interface on the host
2:37machine without any IP address.
2:39It's just a bridge device.
2:41And then what it does-- I like to think of it as it ties
2:45a rope inside here, throws it over, and anchors it
2:49to the host system right there.
2:52So this device is a bridge that allows the container's eth0
2:58to access the rest of the network.
3:00And what it's a bridge to is this docker address.
3:03Notice that this address in here is on the same subnet
3:06as this address here.
3:08So by creating this virtual ethernet
3:10port and this ethernet port inside the container,
3:13effectively what happens is your container
3:16gets an IP address that is going to be
3:18accessible to the rest of the network
3:21through that docker0 interface.
3:25So docker0 works with this virtual ethernet card,
3:29and it ties in to the inside of this container's ethernet zero,
3:34and allows it to bridge through.
3:36If you don't understand or don't care
3:38how exactly the magic happens with the bridging
3:41and stuff like that, it's OK.
3:42Just know that the container gets assigned
3:44an IP address that is accessible via the rest of the network.
3:50And that's how it works by default.
3:52Now I wouldn't just tell you this and not show you.
3:54So what we're going to do now is go and spin up.
3:56I have a very simple container.
3:58It's an awesome container.
3:59I found this guy created-- you might want to write this down
4:03while I'm talking.
4:04So go ahead and write this down on paper so you can use this.
4:06What this-- this is an image that we
4:08are to bring to download off the docker hub.
4:11And it is a completely self-contained web server.
4:15And all it does is serve one page on port 8080.
4:19It's really small.
4:20It doesn't do anything else.
4:21But it's a great way to show network connectivity is
4:25working.
4:26So we're going to install this image,
4:29and then spin up a container based on this image.
4:32And then check out the IP address and stuff
4:34on the system.
4:35So if you haven't written this down,
4:36maybe take a screenshot or something, or pause
4:38and write down, because we're going
4:40to be typing this on our docker host
4:42so that we can get this sample container serving something
4:46on port 8080.
4:47So here we are on the docker system.
4:49I'm actually going to type ifconfig just to show you
4:53what we just described.
4:55So we have eth0 zero.
4:56This is 192.168.1.204.
4:58Oh, I was actually really close in my guess.
5:00I guessed 201.
5:01But 204, this is on my local LAN in my office here.
5:05If we scroll up a little bit, we'll
5:06see that docker0 is created.
5:08Again, this was created when docker was installed.
5:12The doctor daemon is running, and so this exists.
5:14And its address is 172.17.42.1.
5:18that Again, it's close to what I guessed.
5:21It starts with 172, and I think I said 16.
5:25But anyway, on my system it's 172.17.
5:27But this is the range that our docker containers
5:32are going to have.
5:34Notice there's no veth0.
5:37I mentioned that it creates veth0 on the fly.
5:39There's not one there right now, but there
5:40will be in just a minute.
5:42Because what we're going to do is type sudo docker run.
5:46And now we could pull the image.
5:48But if we type run, it will pull it and run at the same time.
5:51And you remember the name, if you look on your paper
5:53where you wrote that down.
5:54It's adejonge/helloworld.
5:59And actually, I want to back here by run,
6:02say -d so goes in the background.
6:04That way we can do things on the command line.
6:06So I'm going to do that.
6:07Asks for my password.
6:09And it didn't actually download it for me
6:11because I'd already pulled that image.
6:12But it will pull the image for you
6:14and give you this long ID string so we can tell
6:16it's running sudo doctor ps.
6:18You see there it is running.
6:19It's called sick_wozniak is the name that it was assigned.
6:22But it's there, it's running /helloworld.
6:25Now, we could hit the IP address of this container on port 8080
6:30and we should see a web page served up.
6:33The problem is, you'll notice, it doesn't tell us what
6:35the IP address, Dun dun dun.
6:38Well, there's a really easy way to get that.
6:40We type sudo docker inspect sick_wozniak It will give us--
6:47well, I'll just hit Enter.
6:48It'll give us this long string of all sorts of information
6:51about the container.
6:53One of the things that it tells us is its IP address.
6:55If we scroll around, we can look.
6:57See there its IP address is.
6:59That's 172.17.0.12
7:01But what I like to do-- type that all out,
7:04do a space, the pipe symbol, and then say grep IP.
7:09And then it will give us a subset
7:11of all the lines that contain a capital I
7:13and a capital P. One of those happens to be the IP address.
7:16And it's really easy to find then.
7:18So 172.17.0.12.
7:21That is the IP address of eth0 inside our container called
7:26sick_wozniak.
7:27Now if we type ifconfig on our host system,
7:32we're going to see there's a new ethernet port created.
7:36It's that veth0 4BB056C.
7:40You'll notice it does not have an IP address.
7:43Like up here, this is the IP address.
7:45There's no IP address assigned.
7:46This is just a bridge port.
7:48This ties our container to docker0 up here
7:52with the 172.17.42.1.
7:56So it ties it to that.
7:57Now how can we tell that it's actually running?
7:59Well, let's open up a web browser.
8:01Go to http://172.17.0.12:8080.
8:10Hit Enter, and sure enough, now we see this.
8:12It says, Hello world from go in a minimal docker container.
8:15This is all that container or all that image does.
8:18It create containers that serve a simple web page on port 8080.
8:22But that's all we want it to do.
8:24So we can tell now.
8:24We know its IP address.
8:26And then on port 8080, it's accessible.
8:28This will be accessible from the rest of our network as well.
8:32Now we know its IP address, we know that it's serving.
8:35So if whatever is running on that server,
8:37knowing its IP address, it's going
8:39to be accessible on the rest of the network on that IP address
8:42as well.
8:43So that's, in a nutshell, how it works when you by default
8:47just use the bridge networking that docker does by default.
8:50That's a way that docker allows you
8:52to spin up multiple containers.
8:55So we can actually say-- let's just hit
8:58the up arrow so I don't have to type it all over again.
9:00Say sudo docker run, the same exact thing.
9:02We press Enter.
9:03Now it's going to create another one, sudo docker ps.
9:07Now we have two /helloworld applications running.
9:10The second one is called tender_feynman.
9:13So if we do sudo docker inspect tender_feynman grep IP.
9:23Now we're going to see this one has an IP address.
9:26Of course, it just incremented.
9:27But, 172.17.0.13.
9:29So if we go over here, we change this to a 13,
9:36we also have one running there.
9:37So even though the containers are both operating
9:40on port 8080, since they've been assigned their own IP address,
9:45they can both run on the same host computer
9:47without any conflicts about the port.
9:50So port 8080 is listening on dot 13,
9:53and it's also listening on our original one, dot 12.
9:57Press Enter.
9:58See, there it is.
9:58Dot 12, it loaded back up.
10:00So now we could stop it over here.
10:02Sudo docker stop sick_wozniak.
10:10So it stopped.
10:11We come back over here.
10:12Now, sick_wozniak was the one with 0.12 as the IP address.
10:16So 0.12.
10:17If we press refresh here, see it's trying to load.
10:22It's connecting to it.
10:23It's not able to connect.
10:25You see it's just hangs.
10:26172.17.0.12, and it's just hanging.
10:30It's just not doing anything at all.
10:32Hopefully that makes sense.
10:33Docker makes it fairly simple to do it automatically.
10:36It's important to know what's happening behind the scenes,
10:38but as long as you know that when you start up a container,
10:41it gets its own IP address on that virtual bridged
10:44that network, you are above and beyond in knowing
10:47how docker handles networking.
10:50And then it's really convenient as well
10:52when you know how to find that IP address using
10:54the docker inspect command.
10:56I hope this has been informative for you,
10:58and I'd like to thank you for viewing.
Advanced Networking
0:00Docker's way of dealing with the networking on containers
0:03is truly elegant with the whole bridge mode and the way
0:06that it creates those IP addresses on the fly.
0:08But it does have a few shortcomings in a local network
0:12environment.
0:13In this Nugget, we're going to learn about port mapping,
0:15port redirection, and also a host networking option that
0:18is available in Docker.
0:20But the problem that we're addressing with these advanced
0:23features is this, now this should look familiar,
0:25this is how I explained the whole bridge networking default
0:29way that Docker handles containers' IP addresses.
0:32So we have this is on our local network,
0:35we have a 192.168.1.204 address.
0:39So that's our host computers' IP address on the local network.
0:42It creates a virtual port called docker0
0:45that has this 172.17 address.
0:47And then when you spin up a container,
0:49it gets assigned a 172.17 address that gets tied
0:54to a virtual ethernet port that is created basically exposing
0:58this 172.17.whatever address to the rest of the network.
1:03The problem is that on our local network,
1:06computers have this addressing scheme.
1:08So this computer over here on my network is 192.168.1.15.
1:13It has no way to communicate with an IP
1:17address of 172.17.0.15 because it's in a different IP range
1:23all together.
1:24So the way IP networks work, this computer cannot directly
1:28talk to a container with this address.
1:32So that's a problem.
1:33Now, we could assign every computer in our network
1:36another address, but that is really a super messy way
1:39to go about doing it.
1:41So the solution that we have is an ability to map ports
1:45from this internal container and map it
1:49to ports on our hosts' IP address.
1:53So we will actually see what's happening
1:56inside the container on a port that's
1:59exposed to our network on the 192.168.1.204 address.
2:03That way these other computers are able to see it.
2:06Hopefully, that makes sense why we
2:08have to have some way for the other computers on our network
2:12to be able to see our container.
2:14And since they don't have this same addressing scheme,
2:16by default they just wouldn't be able to see it.
2:18It would be like right next to it, it's right there,
2:21but I just can't talk to it.
2:22Because that's not how IP addressing works.
2:25So we're going to show you how to-- first, we
2:28can actually do a port mapping.
2:29And that's pretty easy to do.
2:31We're going to use the same hello world application
2:33that we've done before.
2:34That same image that just does a simple web
2:37server that listens on port 8080.
2:40So let's go to the command line and create
2:42an image that maps a port.
2:44So the process for doing this is very similar,
2:46it's like sudo, docker, run -d, for daemon
2:50so it goes in the background.
2:51The name of our cool image is adejonge/helloworld.
2:58But then I actually want to add this option -p 8080.
3:05All right, so what this is going to do
3:07is it's going to create the Docker container,
3:10based on this hello world image just like before.
3:13But here it's -p actually it's for publish.
3:17So it's -p for publish port 8080 on our local host network.
3:22So if I press Enter, it's going to do just
3:24like you would expect it to do.
3:26But if we actually do a docker ps,
3:29we're going to see a little more information.
3:31And the information is here.
3:32So this is the same stuff we had before,
3:34but this extra bit of information
3:36is right here in the ps command.
3:38And what it says is port 8080 is being listened
3:43to on port 32769 of our local hosts' IP address, actually
3:51by every address on the system.
3:530.0.0.0 means that every port on our Docker host system
3:59is listening on port 32769, and it's
4:02going to redirect that to the internal containers' IP address
4:06on port 8080.
4:08So effectively, that means if we go over here to Mozilla,
4:12we can say http://192.168.1.204 port,
4:20and I forgot the port number already :32769, 32769.
4:29And if I press Enter, boom, it loads up this whole Docker
4:34container, hello world from go.
4:35So it's loaded it up on port 32769.
4:38But the important part to see is that it's
4:40on this network, 192.168.1.204, which means computer over here
4:48are going to be able to access it as well.
4:51So when we were-- before since docker0 had this 172.17
4:54address, if we're on the same host computer
4:56we're going be able to connect the containers.
4:58But in order for computers outside of our host
5:01to be able to connect to it, it has
5:03to have an accessible IP address that
5:06matches the same IP address range that the rest
5:09of our network has.
5:10And that's what publishing that port with that -p flag, that's
5:14what that accomplishes.
5:15It allows us to expose that IP address, port 8080,
5:19using mapping it to another port.
5:22Now that's a random port, which isn't
5:24as useful as you would think, you
5:26have to look it up every time.
5:27Thankfully it at least shows us inside here
5:30what the port number is.
5:31But let's actually kill that off.
5:33So sudo, docker, rm -f, evil_kilby.
5:38So it stopped it.
5:39Now if we come back over here, hit refresh, unable to connect,
5:43right.
5:44Because it's no longer running, that container
5:46isn't running at all.
5:48In fact, if we do a ps command, you're going to see,
5:51boom, it's not running at all, Because it was deleted.
5:53So let's create a new one.
5:55But this time instead of that 32769,
5:58we're going to map it to a port that we choose.
6:02So sudo, docker, run -d -p.
6:06Now we're going to say, we want to map port
6:10let's say 8000: to the internal port 8080, on our container.
6:19And then the containers' going to be built on the image
6:21adejonge/helloworld.
6:25So we do that sudo, docker, ps.
6:28We're going to see now it shows us
6:30that port forward is specific.
6:32Instead of picking a random one, like that 32769,
6:36now we've told it specifically, I
6:38want you to listen on port 8000 and redirect that to port 8080.
6:42So now if we come back over here this 32769, which
6:47was randomly generated, has now been
6:50replaced with port 8000, where it should be listening.
6:53And sure enough now it's listening
6:55to that internal containers' port 8080.
6:57Even though it's 8000 on the 192.168 IP address
7:01it's being redirected internally to port 8080.
7:04So computers on the network will be able to access it.
7:07So you can either let it create one
7:09by-- on the fly, a randomized number like 32769,
7:13or you can specifically tell it which port you want it to do.
7:17And you can do this for multiple ports, you can do multiple -p.
7:20So you can do -p 8000:8080.
7:23In fact, let's give a quick example.
7:25Go up.
7:29Port 9000 to 8080 and -p port 9001 to 8080.
7:39Now what this is going to do is it's
7:41going to redirect to port 9000 to the internal port 8080
7:44and also port 9001 to the internal port 8080.
7:50Press Enter so it's done it.
7:52Now if we do sudo, docker, ps.
7:55We're going to see it gives us a list of several of them.
7:57See it comma separated them.
7:59These are the two.
8:00And even though we've exposed two different ports
8:02on our 192.168 IP range, they both
8:07direct to the same 8080 port internally.
8:09So this'll be my last example here,
8:11but so we've done port 9000 and that will load.
8:18Sure enough, we get that.
8:19Port 9001, and press Enter.
8:22And sure enough that loads there, as well.
8:25If we were to try 9002, nope, unable to connect because those
8:29are not being forwarded into that containers' port 8080.
8:32All right so that's how you can manage that.
8:35Now let's actually sudo, docker, rm -f, cranky_loveless.
8:42And sudo, docker, rm -f boring_almeida.
8:50OK, so sudo, docker, ps -a, we have no images running.
8:53Because the last one I want to show
8:55you is what I highlighted in the very first slide,
8:58is that host networking.
9:00So let's say you don't want to go
9:01through the hassle of redirecting ports,
9:03you just want to do a shortcut and actually expose it
9:06automatically on IP address 192.168.1.204, your hosts' IP
9:13address.
9:13That's possible by doing this sudo, docker, run -d -
9:18-net=host.
9:25So net equals host is a new flag.
9:28What this says is, don't use bridge networking,
9:30just share the hosts' IP address, adejonge/helloworld.
9:37Press Enter.
9:38And now sudo, docker, ps, is just
9:40going to show us it's running.
9:41It's called sharp Alameda.
9:43But it doesn't show us any port forwards,
9:45because there are no port forwards going on.
9:47If you do network equals host, there is no more v-ethernet.
9:53So ifconfig, you'll notice there's no v-eth,
9:57there's no virtual ethernet connection at all.
10:00And if we do sudo, docker, inspect oh, what
10:06was the name of it.
10:07Let's scroll up a little bit, sharp_almeida.
10:12Grep IP, if we do this we're going
10:14to see it's not assigned an IP address.
10:16It does not have an IP address assigned, because it's actually
10:19sharing the hosts' IP address.
10:21So what that means we can come over here, 192.168.204,
10:25and we just go directly to port 8080,
10:27because it's sharing the same IP address.
10:30So since that hello world app listens on port 8080,
10:32it's going to be listening on port 8080 of the hosts' IP
10:35address.
10:36Now the reason you can't do this for all of your containers is
10:39we cannot spin up another container,
10:42using the host network, listening on port 8080,
10:44because it's already in use.
10:46That's the beauty of the virtual bridged network
10:49is that it allows you to host multiple programs using
10:53the same port numbers, because it spins up
10:56individual IP addresses.
10:57But if you use host networking, you're limited.
11:00You can only listen-- one container can use port 8080
11:03and that's it.
11:05So there's a limitation, but it does simplify
11:07how things work as well.
11:09And really that covers moderately advanced networking
11:12inside Docker.
11:13It's important to understand how port mapping and port
11:15redirection works.
11:16And when I say port redirection, it's
11:18actually just port mapping where you specify the port
11:21that you want it to map to on your local hosts' IP address.
11:25And then also host networking is just a way
11:27that you can share that host computers' IP
11:30address with your containers.
11:31I hope this has been informative for you,
11:33and I'd like to thank you for viewing.
Shared and Persistent Data
0:00Now by now we realize that Docker
0:01is really amazing for spinning up and taking down
0:05environments and applications really, really quick.
0:07But I'm positive that you don't want
0:10to have a hello world type application
0:12in your real environment.
0:14For them we need external data, or your private data,
0:17so that you can actually serve out a web page that's not just
0:20the default, stock webpage.
0:22Now when we're doing that with Docker,
0:23we want to make sure that the data that we have to serve out,
0:27or to store, is external, and that's because, remember,
0:31containers are ephemeral.
0:32Or they're the kind of thing where we spin the container up
0:35and then we can destroy it, so you
0:37don't have anything actually stored
0:39inside of your container that's important,
0:41so we want to keep it external.
0:43Now we can do that a couple different ways,
0:45like mounting a network server.
0:47And while it is possible to set up like an fstab file,
0:51and set up NFS, or Samba to mount an external shared data
0:57point inside the container, that's
0:59a really complicated way to do it,
1:00and it really is kind of a pain in the butt.
1:02Thankfully, Docker allows us to do that on the host.
1:06So you have your host, your server computer,
1:08and it can mount whatever hard drives or network
1:10shares that you want, and then you can actually share
1:14that with the container inside.
1:15It's really, really awesome.
1:17And why is it important?
1:18Well, I like to think of it like a super spy, right.
1:21Say you are a super spy-- dun dun dun dun dun-a,
1:23dun dun dun dun dun-a -- and you have two things
1:27in your apartment that you have to have.
1:29If your apartment is compromised and the bad guys are coming in
1:32with machine guns, you want to take
1:33your briefcase and your burner phone and get out.
1:36Now the really nice part is everything you have important
1:39is in that briefcase and that burner phone,
1:41so you can take them and then go to your safe house, which
1:45is another apartment across town, and work perfectly fine.
1:48So the data works just like that in a container, right.
1:51You don't want to have anything stored inside the container
1:54that is super important or that you have to have.
1:57You want to be able to get your stuff
1:59and go in a moment's notice.
2:01And so that's how the whole idea of Docker works.
2:03You don't want your data stored inside your apartment, right.
2:06You want to have it portable so you can get it out
2:09really quickly.
2:10And so this is like the host operating system,
2:12the host file system.
2:13This can be network mounted, whatever,
2:15like your home directory, for example, I have listed here.
2:18Let's say you want to access your home directory from inside
2:21of a container.
2:22Well, you can actually just point to this directory
2:26into a container on launch and it will map this folder
2:31to a folder in here.
2:32Now you could, like I said, set up an fstab file
2:35and mount it directly from inside of the container using
2:37network mounting tools, but that is such a complicated thing
2:40to do.
2:41And it's silly to do that because you can actually
2:44just map the drive from your host operating system
2:47into the container.
2:48And so that's what we're going to learn how to do today
2:50because it's a really powerful way
2:52to make your containers that much more disposable, right.
2:56Your data is stored outside of it,
2:58so as you spin it up or destroy it on the fly,
3:01you don't worry about losing any data.
3:04You don't want to store anything important inside
3:06of your container.
3:07And to do that, we mount these volumes
3:09inside of a container when they're really
3:11stored on the host operating system itself.
3:14And that's really easy to do, too.
3:16So we're going to go to the command line
3:17and demonstrate how it's done, but it's just a one liner, just
3:20like everything else in Docker.
3:21It's really awesome.
3:22Now to demonstrate this, I'm going
3:24to use a different container, a different image than we've
3:27used before.
3:28So I'm going to say sudo docker run minus d for daemon,
3:32and I'm going to run nginx-- N-G-I-N-X. And what that is,
3:37it's the nginx web server, so it'll download that.
3:40If you already have it on your system like I do,
3:42it'll just get it going and instantly create a container
3:45and get it served.
3:46Otherwise, it'll download that into your images.
3:48And now if we look at our running containers,
3:52we can see it's called trusting cori.
3:54So let's do a inspect, grep for IP
3:58so we can see the IP address, and we see
4:00the IP address is 172.17.0.24.
4:03So let's go over here and type that in, 172.17.0.24,
4:10I think it was.
4:11Press enter, and sure enough, here we get the welcome page.
4:13So welcome to nginx.
4:14So we can see that it's running, this is just its default page.
4:17There's nothing that it's actually
4:18serving out except its sample page that comes built in.
4:22So I just wanted to show you that's how nginx is working.
4:24It runs on port 80 on that IP address
4:26that we figured out using the inspect command,
4:28but we can also virtually map a folder.
4:32So let's see what I have in this folder.
4:34I have nothing.
4:34Let's create a folder called web, go into the web folder,
4:39and we'll create an index.html file.
4:42And I'm going to say h1, it worked, close that.
4:47It's just pretty simple HTML.
4:50I save this.
4:52And now I'm going to spin up another instance,
4:55or another container of nginx, but this time
4:58I'm going to say pseudo sudo docker
5:00run-- I'm going to say minus d for daemon,
5:03but then minus v for volume, and I'm going to say, what volume?
5:07I want it to be home/spowers/web-- that's
5:11the folder that I want to use for my host system-- and then
5:14a colon, and I'm going to say where I want it to mount inside
5:18of the container.
5:19Now you can read the nginx page on hub.docker.com
5:21to see where things are stored.
5:23I just happen to know that usr/share/nginx/html is where
5:31it serves webpages from inside that container.
5:33So I'm mapping home/spowers/web to be mounted inside
5:37the container in usr/share/nginx/html.
5:39And the nginx image is what I want to spin up,
5:42press Enter it does that again.
5:44Sudo docker ps, see what we have running.
5:47This one's called grave goodall.
5:50So sudo docker inspect grave goodall, grep IP,
5:58and we'll see this one is .25, which is not a surprise, just
6:01increments.
6:02But let's go over here and change this from 24 to 25.
6:07And now if we hit Enter, we'll see "IT WORKED!!!" ,
6:10and it's running inside that container.
6:12However, since we are here and our system,
6:14and it's mounted the one that's on our host system,
6:17if we edit index, and we change it to, let's say, really
6:22worked, save that file.
6:23If we come back over here, even though we haven't spun up
6:26a new image, it's actually reading this data directly
6:29from the host system.
6:30So if we hit refresh, it's changed to "IT REALLY
6:33WORKED!!!" , which is awesome.
6:34Because that means even though the container is running,
6:36we can change our files and it will-- in real time--
6:40get that stuff, because it's just a mapped
6:42our current folder.
6:42Didn't make a copy of it or anything.
6:44It actually directly mapped to this web folder
6:47into the container.
6:48So we can change files here, and it will
6:49be reflected in that server.
6:52So quickly back to our instance here, what we've done
6:54is we've taken the HTML file that we're serving--
6:57and call it the briefcase, or the burner phone, whatever
7:00you want-- we've actually stored that over on the host--
7:04or like, in the pocket of the spy--
7:06and we spin up a container and it's there, so it can see it.
7:09However, we can burn this container down, or burn
7:12that apartment down, and we don't
7:14worry about losing anything important
7:16because all the important parts, that are dynamic,
7:18have been stored inside that volume on the host.
7:21So we can take that to the next container
7:22and it'll serve it up just fine.
7:25So using shared data from your host to your container is easy.
7:28I also said persistent here because if you burn down
7:31a container, or you destroy that container,
7:32your data is going to stay if it was living on the host file
7:36system itself.
7:37So, external is obviously ideal because you
7:39don't want to store anything in a container.
7:42And you can either mount things inside the container
7:45on a network, which is just a horrible way to go about it.
7:47I do not recommend you try to install NFS or Samba inside
7:51of a container as it spins up.
7:52That's just a nightmare.
7:53And it's so simple to mount volumes from the host,
7:57and it can even be a volume that happens to be a Samba share.
8:00So if you have a Samba share that's mounted on your host,
8:04you can take that and mount it using the dash v command,
8:07and it can be a volume inside of your container.
8:10So that's the best way to deal with data when
8:12you're dealing with Docker.
8:14I hope this has been informative for you,
8:15and I'd like to thank you for viewing.
Modifying Containers and Images
0:00The Docker Hub is full of just about every kind of image
0:04that you can possibly imagine.
0:05I mean, web servers, file servers, gaming apps,
0:08all the different things that you
0:10would want to run inside of a container, most of them
0:12are already created at Docker Hub.
0:14However, there are some times where
0:16you get an image that does almost everything you want
0:19it to do and so modifying that image is really
0:23the way that you can tailor it to yourself.
0:24Now there's two different ways to go about modifying an image.
0:27The first way we're going to do is kind of a quick hack
0:30sort of way to do it, but it's completely legitimate,
0:33and it's the easiest way, I think,
0:35to go through and modify an image so that it's
0:38exactly what you want.
0:39And the way you do it is basically you
0:40spin up a container, modify that container,
0:43and then create and save that container as an image itself.
0:46So to do that, we have to be able to attach
0:48to a running container, because to make modifications
0:51to a container you have to be able to connect to it.
0:53Then we're going to modify that running container and then
0:57from that modified container, we actually
0:58create a new image based on the changes we've made.
1:02It's really cool.
1:02So let's go to the Command line.
1:04There's going to be a lot of work on the Command line,
1:07but it's not difficult to understand,
1:08and the result is a custom image that you kind of built based
1:12off one that already existed.
1:14Now the first thing we need to do
1:15is spin up a container so that we can modify it.
1:18So say sudo docker run -d.
1:21I'm actually going to teach you a new flag.
1:23It's - - name and then the name we want to name the container.
1:27So I'm going to say my_nginxtemp, and then
1:32the image that we want to base it off of, nginx.
1:35Now what I've added here is this - -name my_nginxtemp.
1:38You remember when we started container,
1:40it gives it a random, silly name?
1:42Well, if you use this - - name flag,
1:45you can actually set the name that you want it to be.
1:47And that's going to be important,
1:48because it'll get confusing if we're
1:49trying to remember which container we're modifying
1:52and what we want to create it into, et cetera.
1:54So hit Enter, and it's going to create that.
1:57Now if we do sudo docker ps, we'll see the name of it
2:01is my_nginxtemp.
2:02OK, that's really awesome.
2:04Now we want to connect to that so that we can modify it,
2:06but first of all, let's actually do
2:08a sudo docker inspect my_nginxtemp grep IP and look
2:15for the IP address and it's 17.0.27,
2:18so come on over here, 17.0.27.
2:23So we have the Welcome to nginx screen, right?
2:25This is running.
2:25That's what we would expect.
2:26It's just a brand new spun up nginx.
2:28Now if we wanted to connect into that container
2:31so we can do things inside of the environment
2:33on that container, now there's a command called Docker Attach,
2:38and what we would do is say, sudo docker attach, and then
2:42we would say the name of, like my_nginxtemp.
2:44The problem is, this doesn't work
2:46unless the container started with like a Bash script,
2:50and then we kind of like piggyback
2:51onto that Bash script, so even though Attach is still
2:54a viable option, it's definitely not
2:56the most flexible and not the one you actually want to use.
2:59If you want to connect to a running instance or a running
3:03container, we're actually going to say sudo docker exec -i -t
3:10and where we want to connect.
3:11We want to go to my_nginxtemp, and then we
3:15have to say what command we want it to run inside
3:18of that terminal session.
3:19We're going to say Bash.
3:20So if we do that and press Enter,
3:21now we are actually inside that image.
3:25We are inside that container, that running container
3:27called my_nginxtemp.
3:28We are inside there.
3:30So if we go to usr/share/nginx/html,
3:35we'll see in here this is the default, right.
3:38Let's look at that.
3:38Cat index.html, and sure enough, so this
3:42is the Welcome to nginx page that we actually saw over here
3:45on our web browser.
3:47So what if we modified that?
3:49What if we wanted to make our own image,
3:51and we're going to rm index.html,
3:54and we're going to cat into a new index.html,
3:59and we're going to say h1 customized
4:04and then Control-D. Well, actually saying that,
4:07so now we see in here we still have the index.html,
4:09so if we look at it, we're going to see now
4:11it just has that customized h1.
4:13And if we go over here and we hit Refresh,
4:15we would expect that now we would see
4:16that customized thing, right?
4:18But what if we want to create an image that every time we
4:21spin up a container, we get the customized version.
4:24Well, there's an awesome way to do that.
4:25So we have to exit out of the container, so just
4:28type Exit and boom, we are back in our Docker Host, right?
4:33We're back at our regular prompt here.
4:34And we've kind of exited out of that insertion
4:38into the container that we created.
4:40And now if we want to create an image
4:42from the running container, we have to use the Commit command,
4:46and it's actually a really, really simple process.
4:49Sudo docker commit my_nginxtemp, which
4:56is the current running container,
4:58and what image do we want to save it as?
5:01I always like to do my custom images
5:03with the my underscore prefix so that I
5:06know that they're my images that I've created locally.
5:08So we'll just say my_nginx, press Enter.
5:12It gives us that, and now if we do sudo docker images,
5:15we're going to see we have a whole bunch of images here
5:18that were downloaded, but we also
5:19have a new image called my_nginx.
5:23Now what's cool about that?
5:24Well, let's do a sudo docker ps.
5:27We'll see that my_nginxtemp is running, so sudo docker rm
5:31-f my_nginxtemp, sudo docker ps, so there's nothing running.
5:38If we go over here, we'll that this is now completely offline
5:43and just hanging.
5:43It's not doing anything.
5:45Now if we wanted to spin up a brand new image,
5:47so let's say sudo docker run -d my_nginx,
5:54and that's the whole name of the image is my_nginx.
5:57Now I didn't do the name command.
5:58We could name it something, but let's just
6:00spin it like the simplest command
6:01we can, so docker run -d and then my_nginx, press Enter.
6:06It's going to create an image, so sudo docker ps,
6:10we'll see it's created a container,
6:12I mean, and it's running that container,
6:14and it's called high_bardeen.
6:16So sudo docker inspect high_bardeen grep for IP.
6:26Now we'll see the IP address is 17.0.28, so if we go over here,
6:31now this is a freshly spun up container, right,
6:34using our base image that we just created.
6:36Do .28 and boom, it's customized even though we didn't
6:40like go into the container and change that, we've
6:43created a new image that has that customized
6:46page automatically, so we can spin up a hundred
6:49different instances of my_nginx, and they will all
6:52have that customized page that we created by editing the one.
6:56So we've actually started with one image,
6:59created a container from it, modified that container,
7:01and then save those modifications back
7:03to our own image.
7:05It's actually really cool and a great way
7:07to get a specific customized image so you can roll them out
7:11with just one liners, right?
7:12So just do my_nginx, and now we have
7:15another one running on our system
7:17serving out that customized page.
7:19Sudo docker ps, and now we have two different containers,
7:24and they're based on our custom image.
7:26It's really a powerful way to customize your image
7:30so your containers are automatically exactly how you
7:33want them when they start up.
7:35We actually learned a lot of really useful information.
7:37We learned how to attach to running containers
7:40and, again, I don't recommend you use the Attach command,
7:42because that doesn't always work,
7:44but if you do that exact IT and you tell it to run Bash,
7:48it'll always work.
7:49You can always get into the container.
7:50So we learned how to attach to it.
7:52We learned, actually added to this,
7:53how to name a container so that we
7:55don't have to use those funny names that they always come up
7:58with.
7:58If you want to have your own custom name, you can do that.
8:00And we learned how to modify the container
8:02and then how to create a brand-new image based
8:05on a running container so that we can have it
8:07as customized as we want.
8:09I hope this has been informative for you,
8:10and I'd like to thank you for viewing.
Creating Images from Scratch
0:00OK, I'm not going to lie, this is
0:01going to be a fun Nugget because we're
0:03going to take all of the stuff we've learned about Docker
0:05and we're actually going to create our own images
0:08that we can then deploy.
0:09And we're going to do it from scratch
0:11as opposed to from a running container
0:13and creating an image out of that.
0:16Well, first we're going to learn what a base image is,
0:18but we're going to start with a base image,
0:20create our own Dockerfile, which is a recipe,
0:23and then we're going to build images
0:25from scratch right on our computer
0:27so we can then deploy those images as we see fit.
0:31Now, I said Dockerfile, and it's important to realize
0:33that a Dockerfile is a lot like a recipe
0:36that your Docker system will use to create images--
0:40like fresh images that have never been containers before.
0:43We're not going from containers back into images.
0:46We're actually starting with this Docker file.
0:49And I just wrote on here some silly things
0:51like one cup of Debian, two tablespoons of PHP,
0:54and two cups of application.
0:56Mix well and open the port.
0:58Regardless, what this does is this recipe
1:00allows you to create an image.
1:01And we started at the very beginning
1:03of when we learned about Docker, we
1:06created a one-line Docker-ized application.
1:09What we did is we started with a base image,
1:11and a base image is just that.
1:13It's an image that does nothing but set up the environment.
1:17So for example, Ubuntu is the name of an image.
1:21I think we used CentOS before, so CentOS is a base image.
1:26And all that does is create for you the environment
1:31that looks like Ubuntu.
1:32So the dependencies and all of the things
1:35that an Ubuntu system has, except for a running kernel
1:38and all that stuff, but the other dependencies and files
1:42that you would expect in a Ubuntu system,
1:44that's what a base image is.
1:46So there's no application in the base image.
1:50This is just setting up your environment.
1:52So when you see images that are built from Dockerfiles, which
1:56is what we're going to do in this Nugget,
1:58almost every one of them starts with a base image of some sort
2:02because it gives you that environment
2:04to run your application in.
2:06Now, we've been working in the past NGINX,
2:09so I want to quickly look at what
2:10NGINX Dockerfile looks like.
2:12Because we've used the NGINX image,
2:16but how is that image built?
2:17Well, it's a lot simpler than you would think.
2:20So let's look at the NGINX Dockerfile,
2:23and then we're going to go and create our own Doctor
2:27file so we can create our own fresh, from scratch images.
2:31So here, back in our Docker host computer,
2:33I'm going to say LS so we can see
2:35I copied from hub.docker.com the Dockerfile that
2:39exists for NGINX.
2:41So let's just quickly look at that.
2:43We're going to look at-- this is the Dockerfile.
2:45This is the entire recipe, if you will,
2:48for creating a Docker image.
2:51And there are some important key words
2:53that we're going to look at.
2:55It says, basically, this is from what base?
2:58And the base they're using is Debian,
3:01and then they specify with a colon what version of Debian--
3:03Jessie.
3:04That's the name of the version of Debian
3:07that they're choosing.
3:08Now, if they were to leave off this colon Jessie,
3:10it would just pull the latest Debian-based image
3:13and that would most likely work fine as well.
3:16But anyway, from is how you tell it what base image
3:18you want to start with.
3:19What environment, what sort of operating system
3:24is the application going to expect?
3:26And this one is going to expect a Debian system,
3:28so that's the environment we're going to give it.
3:30Maintainer is pretty self explanatory.
3:32Who maintains this image?
3:35We'll put my name in there.
3:37And then there are run commands.
3:39So it starts with the command for the Dockerfile.
3:42And it's all in caps.
3:43That's just a convention.
3:44But run, and then it will run this command
3:46as it's creating the image.
3:48So it'll run that.
3:49Then it actually installs an apt key
3:51and then we download that apt repository.
3:54It sets an environment variable using the ENV command.
3:57Down here, it runs some more and it runs apt-get update,
4:01apt-get install, these packages, and then
4:04it cleans up after itself and removes
4:06some files in the apt system just to make it
4:09a smaller image.
4:10But it's basically just doing command line things.
4:12Run tells it to do command line things,
4:15and you'll see there's just one command here.
4:16It's because they've strung together one long command
4:19into three lines.
4:21That's what this backslash means.
4:22But you can have a run command-- as many as you want-- in a row
4:25and it will run them.
4:26And then down here, you see some more run commands.
4:28It does symbolic linking.
4:29So the standard output and standard error
4:33actually gets redirected into a file,
4:35and then it does a volume where we can share
4:37volumes between containers.
4:39Expose opens up ports so those ports can be accessed.
4:43And this is an NGINX, so you want port 80 and 443,
4:46the web ports, to be open.
4:47So that makes sense.
4:48Expose opens up that firewall so you can actually
4:51get to those from the outside.
4:53And then the last one is a CMD.
4:55It stands for command.
4:57And this is what it actually runs.
4:59It runs the NGINX daemon.
5:01And so we're going to create something like this.
5:03I wanted to show you the NGINX one
5:05because a web server is a fairly complex beast,
5:08and this is all it takes to install and create
5:12an image that runs a web server.
5:14It's fascinating how efficient Docker
5:17is in allowing you to do some simple things.
5:19So we're going to create a Docker image next.
5:22And when we create that image file-- that Docker image--
5:26we're going to call it myapp or mycount or whatever.
5:28And then we can spawn off multiple containers, just
5:31like if it was an image that we downloaded from Docker Hub
5:34proper.
5:34We're going to create a complete image on our system.
5:38So we need to start with a build directory.
5:42Now, I've already created a directory for us,
5:44and I've called my_counter.
5:46So let's go into that directory.
5:47You can see it up there-- my_counter.
5:50And inside here, I have one file.
5:52Now, this is the app, if you will.
5:54Remember before we created an app that counted 1 to infinity.
5:58Well, that's what I did here.
5:59I just created a file that's a script that
6:01will do that same thing.
6:02So let's look at it really quick.
6:04This is all that's in there.
6:05It's a bash script, and says while true, increment x,
6:09and then echo x to the screen.
6:11If we actually execute this, we'll
6:12see it just counts forever-- one, two, three,
6:15four, et cetera.
6:16So that's the application that we're going
6:18to create an image around.
6:21So we're going to Docker-ize this application
6:25and create an image that will auto-start it
6:27when that image is turned into a container and started.
6:32Now, I said this is a build directory.
6:34And inside this directory, we're going to create a Dockerfile.
6:39So I'm going to say VI capital D Dockerfile right here.
6:43So that's the convention.
6:44We name it Dockerfile.
6:46And it's going to be an empty file at first,
6:49but we're going to create one just like that NGINX Dockerfile
6:53that we saw.
6:53So we're going to say from-- I'm actually
6:55just going to say from Ubuntu.
6:57I really like Ubuntu for a lot of reasons,
6:59so that's what I'm going to use as my base image.
7:01And again, that base image, it's going
7:02to download from Docker Hub.
7:04But that just gives us an environment that is Ubuntu.
7:08That's the environment that the container is going to have.
7:12And it's going to work like a Ubuntu system,
7:15but just inside a Docker container.
7:18We'll say the maintainer-- Shawn Powers.
7:22Shawn@shawnshouse.com, which is not my real address.
7:24So please don't email that poor person if such a person exists.
7:28And now, this was not in the NGINX Dockerfile,
7:31but it's something that we're going to put in ours.
7:33We want to have that file-- that countet.sh file-- we want
7:38that inside of our container.
7:39Now, it's in our build directory that we're in right now,
7:42and so what we're going to do is we're
7:44going to use the copy command.
7:45Now, we could also use a command called add
7:47and it would work the same way.
7:49I'll explain the difference in a moment.
7:50But copy counter.sh, which it looks in our local directory--
7:55our build directory.
7:56And so that's the source.
7:58And then where do wer want it inside the container?
8:00Well, I'm going to say user/local/bin/counter.sh.
8:05So I want to copy it from our build directory into our image
8:09at that location, and then I'm going to run chmod +x
8:13user/local/bin/counter.sh.
8:17And that's to make sure that that's an executable file
8:21inside of my image.
8:22Remember, run just does a command line thing inside
8:25of the image that we're creating.
8:26And then the CMD.
8:28Now, CMD again means command.
8:30What command do I want the image to automatically execute
8:34when it's turned into a running container?
8:36Well, we put it in brackets and then quotations--
8:39user/local/bin/counter.sh.
8:43And we know that's going to be there
8:44because we just put it inside with that copy command
8:48up there.
8:48Now, I said there is a difference between copy
8:51and add.
8:52We could actually change this to add counter.sh,
8:59and this would work just the same.
9:01So if you're looking at other people's Dockerfiles,
9:03you may see the word add instead of copy.
9:06The difference is copy just copies it directly.
9:08So whatever we have here in our build directory,
9:10it's going to copy it to that image.
9:12If you say add, this source could be a file.
9:17It could be a TAR zipped file.
9:19So if this is a TAR.gz file, it's
9:21going to extract it and put it in the destination.
9:25And if you use the add command, this could even be a URL.
9:28So if there's a file listed somewhere,
9:30like if you're doing WordPress and you
9:32want to download the latest WordPress TAR.gz,
9:35you could put a URL in this first place
9:37and it will download it and then put it in the destination.
9:40But if you're just doing a local copy from your build directory,
9:45the convention is to actually use the copy command.
9:48So I'm going to do it the correct way and that's
9:50what it will do.
9:51It'll copy it into my image.
9:52And honestly, that's it.
9:54We're done.
9:55We've done everything required to build a Dockerfile that
9:58will work for us.
9:59So let's save this file.
10:01And now if we do LS, inside of our
10:03build directory is this counter.sh file, which
10:06we looked at and it works, and this new Dockerfile.
10:09So now if we wanted to create an image from this,
10:13we do sudo docker build and then dash t for tag
10:18and what we want to name it.
10:19I'm going to say my_counter.
10:23Remember, I always like to name my own personal images
10:25with that my prefix letting them know it's mine.
10:28And then what build directory do we want it to use?
10:31I'm going to say dot for the current directory that I'm in.
10:34So we do that.
10:36It does all the things.
10:37It downloads anything it needs.
10:38I already had that Ubuntu base directory.
10:40So it actually did that.
10:42But then it created stuff, it copied it,
10:44it made sure it is executable, and it created an image.
10:47We can make sure it created that image by saying docker images.
10:51Let's see what images we have.
10:52Well, we did my NGINX that we did in the different Nugget,
10:56and now we have this my_counter image.
10:59Now, this is an image on our system.
11:01So we could simply create a container from it.
11:03Sudo docker run -d my_counter and it's going to run that.
11:09Sudo doctor ps, and we'll see it's there.
11:12My_counter is running.
11:14It's called dreamy_yellow.
11:15So if we say pseudo docker logs dreamy_yellow,
11:22we'll see that it's counting.
11:23It's going away.
11:24So if we say that again, we'll see it's counted even higher.
11:26So it's actually working, and it automatically
11:29started our application upon deployment.
11:32So we actually have created an image
11:34from scratch using just those few lines in the Dockerfile,
11:38and now we have a fully-functional image
11:40that we can create a container from-- as many containers
11:43as we want.
11:44So while our example was a very, very simple,
11:47you don't have to stop with simple.
11:49Your recipe or your Dockerfile can be very complicated.
11:53If you need to add dependencies or unzipped files
11:55or you want to put specific things in specific places
11:59on your image, you can do that and then
12:01your deployment is as easy as deploying
12:04your image using Docker fun from that image that you created.
12:07And it's so simple.
12:08I mean, our simple example was just five lines.
12:13It was just lines in the Dockerfile,
12:15and we created a fully-functional image
12:18that we can use to spin up containers
12:20running our app, which happens to just count.
12:22But I mean, it's an app that does something.
12:24Any app you have you could do that same thing with
12:27and create your own image.
12:29I love when all the things that we've learned come together
12:32and we're comfortable doing things.
12:34We understand what a base image is.
12:36We understand now that a Dockerfile is just
12:38a simple recipe for creating that image.
12:40And we learned that building an image from a Dockerfile
12:44is a simple one-line executable just
12:46like everything else in Docker.
12:48It's exciting, and I hope this has been informative for you.
12:51I'd like to thank you for watching.
Containers Working Together
0:00In this Nugget, we're going to learn
0:01to have containers work together so that they can execute
0:05on the same data but still working
0:07separately and independently.
0:08So independent execution-- they're
0:10going to share that input and output,
0:12but rather than use the traditional host file
0:14system that we've done in other Nuggets
0:16for getting data outside of a container,
0:19we're actually going to abstract even the idea of data storage.
0:23And we're going to have a container that
0:25strictly stores data.
0:26That's confusing, don't worry.
0:28I'll explain why it works in just a second.
0:30See we have two apps that we're going to be working together.
0:32We have the counter app that we've been dealing with,
0:35slightly modified, but just counts one, two, three.
0:37We have an image we're going to create for that.
0:39And then our standard Nginx web server.
0:42And the idea is we want the counter app to output a number,
0:46you know, like a one, two, three, four.
0:48And then we want the web server to be
0:50able to show us that number.
0:52So we want to be able to refresh the web page
0:54and have that number show up.
0:56Now we could just do -v and get a similar host volume like
1:02/home/spowers/web and we can map that to where this
1:07output's it's counting.
1:09And then we could mount this same folder inside here
1:12into the user share Nginx HTML directory.
1:15And that would work just fine.
1:17It would work and it would be functional.
1:18It would be fine.
1:19The problem is what if we wanted to send
1:21our setup to another user on another system.
1:25Well, they would have to figure out what their own data storage
1:30spot on their server is.
1:31Unless their name happens to be Steve Powers,
1:34they're probably not going to be /home/spowers on their own
1:38machine.
1:38So if we abstract out the host operating system, like the file
1:43system on the host, and we store it inside of a data container
1:48that we create, it allows us to say,
1:50OK, here are all of my images, you spin them
1:55up with containers named like I tell you
1:57and it will just work, regardless
2:00of what your underlying file system looks like.
2:03So hopefully it makes sense of why we would want to.
2:05It kind of seems like a step backwards, right?
2:07Like OK, well, we had a common place for the data,
2:09why are we now putting that inside of a container when
2:12we don't have to.
2:13It's kind of like going from a container to the host
2:15into another container.
2:16But the idea is it abstracts out where the data is stored
2:20and gives us a common place that multiple containers can
2:24reference.
2:25And it's, again, a really simple way to do that.
2:27But that's the reason we're doing it.
2:28So now let's go ahead to the command line
2:30and actually show what that looks like in practice.
2:32Because a data only container functions slightly differently
2:36than the containers that we're used to that
2:37are constantly running an app.
2:40Now, the first thing I want to do
2:41is create a container that will store
2:44the data for our other two containers to look at.
2:47OK?
2:48So to do that we're going to say sudo docker.
2:51I'm just going to say create, because it
2:53doesn't have to run, right?
2:54It doesn't-- here's a cool part.
2:55A container doesn't even have to be
2:57running in order to share its data
3:00volumes with other containers.
3:02So we're just going to create it and it won't even be running.
3:05How cool is that, right?
3:06It's just going to be created.
3:08So sudo docker create.
3:11We're going to name it my_data.
3:14And the reason I'm going to name it
3:16that is so that I can reference this container when I start up
3:20the other containers that are going
3:21to look to it for its data.
3:23Now we're going to say -v for volume.
3:25And I want to create a volume inside of it,
3:28/usr/share/nginx/html.
3:33And I want to use the ubuntu image.
3:36So that's how it's going to do.
3:37Now hopefully this makes sense.
3:38We're going to create it, I'm going to name it my_data.
3:41Now this -v for volume, you'll notice
3:43I didn't map it to anywhere inside the host operating
3:46system.
3:47I just wanted to create a volume that it can share out.
3:50So this has a folder inside of it that it's going to have
3:53/usr/share/nginx/html.
3:55This is going to be a volume created in this container--
3:58even though the container's not doing anything
4:00other than sitting there-- it's going to be this common storage
4:03area for this volume.
4:04OK?
4:05Now this volume folder name should look familiar.
4:07That's where the Nginx thing will eventually look for HTML,
4:10but nonetheless, this is going to be a central repository
4:12that it's going to have.
4:14So we hit Enter, it's created it.
4:16Now if we do sudo docker ps, oh, it's not running.
4:19Right.
4:20We didn't run it, we just created.
4:21So sudo docker ps -a will show us, sure enough, it's there.
4:27It's called my_data and it's sitting there,
4:28even though it's not running, it has
4:30a volume that we will be able to access from other containers.
4:34So let's start up an Nginx container.
4:36sudo docker run -d --volumes-from my_data nginx
4:46So what are we doing here?
4:47Well, sudo docker run -d so it runs in daemon mode.
4:50This is the new one. --volumes-from my_data.
4:54Now notice we didn't specify any folders on our host operating
4:57system.
4:58We just said take the volumes from this container
5:02and use them, mount them, right?
5:05So volumes from my_data, which we know is running right here.
5:09Now, what volume is it going to get from my_data?
5:11Well, this one right here, right?
5:12The /usr/share/nginx/html volume.
5:14So it's going to get that.
5:16If we press Enter it'll actually start up. sudo docker ps.
5:20We're going to see it's called naughty_hoover so sudo
5:24docker inspect naughty_hoover |
5:28grep IP
5:29All right.
5:30So it's 0.39-- let's go over here 172.
5:3417.0.
5:36I already forgot what it was.
5:3939.
5:40OK.
5:4139 press Enter.
5:42Now we should get an error.
5:44And sure enough, it says 403 Forbidden.
5:47Why is it's saying that?
5:48Why is Nginx giving us an error?
5:50Well, because it's using the volume from my_data
5:54but there's currently nothing in that volume.
5:56So it just sees an empty folder.
5:58So Nginx-- it's using the volume correctly.
6:01That's like a good way for us to test that it's actually
6:03using the volume.
6:04So now we have to have an application that's
6:07going to actually put something in that data volume
6:10so that Nginx will see it.
6:12And I've just so created such a thing.
6:14So see how I have, let's see, I have a new build folder
6:17called my_webcounter.
6:18If we go into there, my_webcounter,
6:21you'll see I have a script called webcounter.sh.
6:24Let's look at that really quick.
6:26Now this should look very, very familiar.
6:28This is just a one, two, three app that we had before.
6:31However, I've changed it a little bit.
6:33So instead of just echoing one, two, three to the console,
6:37it actually echoes a little HTML magic here.
6:40So this is like a line of HTML.
6:42It centers it, it makes it big, and puts the number
6:44in the middle there, and rather than just print it
6:46to the screen, it redirects it to a file /usr/share/nginx
6:49/html/index.html.
6:53OK?
6:53That's the location that it's going to write
6:55this over and over and over.
6:57I'll quit.
6:58Let's actually build this so sudo docker
7:02build -t we're going to call it my_webapp dot.
7:08OK.
7:09So it's created that image and now
7:11if we spin up a container from this image,
7:14so we say sudo docker run -d --volumes-from my_data.
7:24So it's going to get that same volume that the Nginx
7:29container's looking at from that my_data container that's
7:32just sitting there idle.
7:33So it's going to get that volume.
7:35And we actually want to run from the image my_webapp
7:39so I'll press Enter.
7:40It spins it up.
7:41We do sudo docker ps.
7:43We'll see, sure enough, here it is.
7:45This is our web counter that's running an evil_elion.
7:49Now if we go over here and I hit Refresh,
7:52you should see-- if everything is going right--
7:55that web counter that is a writing
7:57over and over that a number to the shared volume
8:01on the my_data container.
8:02And then this Nginx container is looking
8:05at that same shared data container
8:08and reading that HTML file from that shared volume.
8:11Let's see.
8:11If we hit Refresh Boom.
8:1333.
8:14Let's hit Refresh again.
8:1535.
8:16Hit Refresh again.
8:1738.
8:18So it's actually working.
8:19They are working in concert and if we look back
8:23at this drawing, what's happening our counter app
8:27is doing that little string of HTML
8:29that's creating like 35, 36, 37 as an HTML file.
8:34And it's writing it directly to this data
8:36only container called my_data.
8:41And then this web server has this data only container volume
8:46mounted as well.
8:47So when it looks to serve out it's HTML,
8:49it's actually looking in this shared volume
8:52and it sees an HTML file there.
8:55So sure enough, it serves it out and they're working in concert
8:59without needing any reference to the underlying file system.
9:03Which means that we've created a completely portable pool
9:07of applications that are working together.
9:09Because these can be delivered to anybody.
9:12They can be delivered to your computer
9:15and as long as you name it the data only container properly
9:18and you point them volumes from that data container,
9:22it doesn't matter what your operating system's file
9:25system looks like.
9:26You don't have to reference the file system at all.
9:28You can reference this shared volume
9:31and then share your data from inside there.
9:33And while it seems like it adds a layer of complexity,
9:36what it gives us is this really awesome ability
9:39to allow our system to be completely portable.
9:42They're still independently executing.
9:44They're sharing that input and output,
9:46but rather than sharing it off the host file system,
9:48they're sharing it from a data volume container that doesn't
9:52even have to be running.
9:53It just has to be existing and created
9:55so that the running containers, the other ones,
9:57can reference it.
9:58I hope this has been informative for you
10:00and I'd like to thank you for viewing.
GUI Tools for Docker
0:00Today on Dockerise Your World, I'd
0:02like to talk about Docker GUIs.
0:05Specifically some options that we
0:06have for administering the command line Docker program
0:11with some GUI front ends.
0:13Now, we are going to look at one called Dockerui.
0:16And this is one that I recommend that you install,
0:18even if you're just a command line nerd
0:20and that's all you want to do is the command line stuff,
0:22because it's the most efficient.
0:24Dockerui will give us a few advantages
0:26that makes it worth installing.
0:27I'm also going to mention and list a few full GUI interfaces.
0:31We're not going to go through and install them
0:33because, truly, I want you to understand how Docker works.
0:36I don't want you to shortcut it and just use a GUI,
0:38but I want to mention them because some people really
0:40prefer GUIs.
0:41And, depending on your environment,
0:43it might be the only way that you're
0:44going to be able to really use Docker.
0:46But first of all, I want to install Dockerui and show you
0:49what it does for your Docker world.
0:52Now you're very familiar with doing
0:54all sorts of Docker commands.
0:56Like Docker ps, which I'll do right now
0:58to show that I have a few containers
1:00that are running from a previous Nugget.
1:02They're still sitting here running.
1:03Now, Dockerui is easy to install on your system
1:07because it's just a container.
1:09It's an image that we're going to download from Docker Hub
1:11and install.
1:12It's really super cool.
1:13So sudo docker run minus d.
1:17Now we need to set up a port forward,
1:19so dash p 9,000 colon 9,000.
1:23So that the local host port 9,000
1:25will point to that internal container.
1:27If you're running a system that has SELinux,
1:31you may need this flag.
1:32And it's not going to hurt even if you don't need it.
1:35But privileged.
1:38So privileged.
1:39That will allow it access to the Docker socket interface.
1:43Then we have to set up volume so that /var/rundocker.sock
1:50on our main system maps up with /var/rundocker.sock.
1:55That's the socket interface on our internal container.
1:59And then just the name of the image,
2:01which is dockerui/dockerui.
2:05And it's going to say, hey I, don't have that.
2:07So it's going to pull it off of Docker Hub.
2:09It's going to download it and install it.
2:11And then, boom.
2:12It's automatically running.
2:13If we do a sudo docker ps, we'll see-- sure enough-- it's right
2:16there.
2:17It's called compassionate_ardinghelli.
2:20Boy, this is a perfect example of why naming your containers
2:24maybe makes sense.
2:25Because what a big, long thing to try to type out.
2:28Anyway, it's running and that's fine.
2:31What we're going to do now is come on over here.
2:33Now, we don't actually need to know the IP
2:34address of that container.
2:36Because remember, we set up that port forward.
2:37So we can just say http://127.0.0.1 port 9000.
2:46Or local host port 9000.
2:49And it's going to show us the Dockerui interface.
2:52Now there's not-- you can't do everything with this.
2:55This isn't where you're going to browse Docker Hub or anything
2:57like that.
2:58But this will give you a really good image of your currently
3:02running systems.
3:03Including some statistics and that sort of thing.
3:05We can look at the individual containers that are running,
3:08the images that we have on our system.
3:11We can actually do things like delete,
3:13remove those images if we want.
3:16Information about our system in general.
3:18But if we go to our running containers--
3:20we can go to this-- let's see, go to nginx.
3:25So we go to the nginx container.
3:26And this is a lot like doing an inspect command on the Docker
3:31interface.
3:31But it just shows us some of the information
3:35that we actually might want to see.
3:37So here's some information about that.
3:40If we actually click on the name of it,
3:44it'll show us the stuff about the container,
3:46including the IP address.
3:48So all that time where we grepped for IP
3:51in the inspect command, now we can actually just go in here
3:53and quickly have a GUI interface.
3:55In fact, this is nginx.
3:57Let's see.
3:57From a previous Nugget, we were integrating containers.
4:00Let's see, if we paste that address in there,
4:03if it's still running.
4:04And sure enough, it's still running.
4:06Our web counter from a previous Nugget
4:07has now counted up to 70,901.
4:10But the Dockerui is a really neat interface.
4:13More for information gathering than anything else.
4:16You can do a few things, like I said.
4:17Remove images with it.
4:18But truly, its advantage, or its best purpose,
4:22is to look at information on your running system.
4:25That's really what it shines.
4:27Now there are some other GUI options.
4:29I'm going to mention them, and you can go check them out for
4:31yourself.
4:31But since it really isn't going to help you learn Docker
4:34anymore, I'm not going to install them or anything
4:36like that.
4:37But I do want you to be aware of them.
4:39Because you may end up needing them if
4:41you want to install and run Docker on your Windows or OS X
4:44system.
4:45I was going to give you URLs for each of these,
4:48but that actually has bitten me in the behind a few times.
4:51Because URLs change, and then here this video is.
4:54And you're like, that URL isn't right.
4:56So what I'm going to urge you to do is check these out,
4:59and just Google these names like with the word Docker.
5:02And you'll be able to find their current URL
5:05and download the software that's there.
5:07I want to talk briefly about them.
5:08Kit-imatic or Kite-matic.
5:09I'm almost positive it's Kit-imatic,
5:11but Kite-matic sounds cooler.
5:13It's from the folks at Docker.
5:15Now they released this.
5:17Unfortunately, right now, it's really, really buggy.
5:21About half the time I install it on a system,
5:23it just doesn't start up right even.
5:25It's just horrible.
5:26So you definitely do not want to use this in production.
5:28But it has an incredible GUI interface
5:31where you can start, stop, download, browse Docker Hub,
5:34all that sort of stuff.
5:35It is a great GUI interface.
5:36But most importantly, it allows you to run Linux containers
5:41on Windows and OS X. Because what it does
5:44is, along with its GUI software, it actually
5:46installs a Linux virtual machine on your Windows or OS X
5:51machine.
5:51And that way, you can use those Linux containers on it.
5:54So Kitematic is a great way to down--
5:56you can download it and start playing with Docker right away.
6:00But I urge you to make sure you know what's going on.
6:03That's why I save this to last.
6:04I want you understand Docker before you take the shortcut
6:07and use a GUI.
6:08But if you're using Windows or OS X,
6:09this is the way that you want to check out Docker on your system
6:12without installing Linux somewhere else.
6:15Shipyard, it's a lot like Dockerui
6:17with some more features.
6:19As far as you can spin up images,
6:22or spin up containers from images, and that sort of thing.
6:24It also will manage multiple Docker hosts
6:27in the same interface.
6:28So Shipyard is worth looking at.
6:30Panamax is-- it's interesting.
6:33Panamax will manage Docker hosts along with other applications.
6:38It has its own marketplace, which is a little odd.
6:41But I wanted to mention it because it's
6:42a fairly mature and robust application that you can
6:46use to have a GUI interface.
6:47It's web-based, so is Shipyard.
6:49Kitematic is the only one I know of that's
6:51not web-based interface.
6:53It's actually a GUI tool on OS X and Windows
6:55that allows you to interface with Docker.
6:57But if you're interested in GUI interfaces, check these out.
7:00Even if you're not interested in GUI interfaces for manipulating
7:04Docker, I urge you to install Dockerui
7:06because it's very simple.
7:07It uses almost no resources, and can
7:09be a really nice interface for clicking around your running
7:13Docker system.
7:14I hope this has been informative for you.
7:16And I'd like to thank you for viewing.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
$708
seat / year