‫Is in this lecture, requirements are that you know how to start a container.
‫What we're going to be doing at the command line here is running Docker commands to understand what's
‫going on inside a running container. There's multiple ways that we can see what's going on in there.
‫We've covered the top command, which is a process list of what's happening inside the container, but there's
‫other stuff we can do as well. We can use the inspect command to actually see the details of how the
‫container started and how it's configured.
‫We can look at the stats command which actually gives us a view of all of our containers and the performance
‫statistics for each one of them in a real time stream.
‫Let's dive in. In order to look at some of these commands and how they act with containers, we're going
‫to need to actually start a few containers.
‫The first one we're going to start is an Nginx container like we've done before.
‫docker container run -d --name, lets call it nginx, and we're going to use the Nginx image.
‫OK.
‫Then the second one we'll use is another MySQL server so docker container run -d --name
‫mysql and we'll also need to specify the environment variable like we did before.
‫So, RANDOM_ROOT_PASSWORD=true
‫And then the mysql image.
‫Note that with the mysql image, as you can read on Docker Hub, it'll tell you that you have to specify one of
‫three options for the password.
‫Either you can specify a password in the command line, you can let it use no password, or you can do
‫what I've done here which will have it, on first boot, actually create a random password like we did in
‫the exercise a few minutes ago.
‫OK.
‫If we do a docker container ls,
‫we should see two running containers.
‫Great.
‫So we've used docker container top before.
‫If I just specify the mysql, you'll see that it actually lists the processes running inside that
‫container.
‫We can do the same thing, docker container top nginx, and that lists the processes running
‫in that container.
‫Another way to look at how this container is configured when it was started and all of its metadata
‫config, we can actually use the inspect command. docker container inspect. Then just say my mysql
‫and we get back a JSON array of all the data about how this container was started.
‫A lot of this will start to make sense as we go throughout this course.
‫As you can see, it is obviously a lot of data about this container. But as interesting as this config
‫data is, it doesn't tell us anything about the active container and what it's doing.
‫So let's use the docker container stats command.
‫If I give you a --help, you can see that it allows us to actually specify a container to only
‫show that. Or, if we just leave it empty and just type docker container stats,
‫we actually get back a streaming view of live performance data about our containers.
‫Unfortunately, it only shows the container ID, not the container name, but you can see by the CPU column
‫that every few seconds something is changing.
‫Obviously in a production environment, you're going to have a more complicated monitoring and performance
‫solution for tracking all this stuff.
‫It's really great for local machines where you need to make sure that you're not exhausting your
‫machine's RAM, because maybe you have too big of a database, or they're not filling up the hard drive
‫because of an out of control process.
‫This is a quick command to just make sure that everything is within its memory limits, and that it's not
‫using a ton of networking, and the block I/O is actually for your disk performance.
‫As you can see, these containers aren't really doing anything because we haven't asked them to do
‫anything. To get out of this, Control c. Let's do a quick docker container ls so that we
‫can match the container ID up with our stats command.
‫So you can see the mysql server was the one actually using almost 400MG on startup.
‫Just to recap what we did in this lecture, we actually first used the docker container
‫top command to list all the processes that will be running in a single container.
‫Then we got into container inspect. In container inspect,
‫we can actually see how the container was run, what was run with it, and what the environment and options
‫were when it started. Then container stats, which is sort of a live updating ability to see all containers
‫and what resources they're taking up as they're running.