DOCKER - 12 View activities in a container
Hello everyone and welcome to this introductory course to Docker.
Today we are going to run Docker commands to understand what is happening in a running container. There are several ways to see what is going on there.
We talked about the top command, which is a process list of what's happening in the container, but we can also perform other actions. We can use the inspect command to see the container startup and configuration in detail.
We will see the stats command which gives us a view of all our containers and statistics on their performance for each of them in a real-time feed.
In order to examine some of these commands and how they affect containers, we will first need to start a few containers.
The first one we will start is an Nginx container, as done before. docker container run -d --name, let's call it nginx, and we'll use the Nginx image.
Then the second server we will use is a MySQL server. Docker container run --d --name mysql and we will also need to specify the environment variable as we did last time.
So RANDOM_ROOT_PASSWORD=true and mysql.
If we make an ls docker container, we should see our two containers running.
We have already used docker container top.
If I just specify mysql, you'll see that it actually lists the processes running inside that container.
We can do the same with nginx, docker container top nginx, and the list of processes running in that container.
Another way to see the configuration of this container when it starts and the configuration of all its metadata is to use the inspect command. Docker container inspect. Then I type mysql and we'll retrieve a JSON array containing all the data about when this container started.
As you can see, there is obviously a lot of data on this container. But as interesting as this configuration data is, it doesn't tell us anything about the active container or what it's doing.
We will therefore use the docker container stats command.
If I add –help, you can see that we have the option to specify a container to show only this one. Or, if we just leave it empty and just type docker container stats, we come across a streaming view of our containers' live performance data.
Unfortunately it only shows the container ID, not the container name, but you can see, in the CPU column, changes every few seconds.
This is useful on local machines where you need to make sure you don't exhaust its RAM, because you might have too big a database, or they don't fill up the hard drive because of an unsupervised process.
This is a quick command just to make sure everything is within memory limits and not using a ton of bandwidth
As you can see, these containers don't do anything because we just didn't ask them. To get out of it, Control c. Let's quickly make a docker container ls so we can match the container ID with our stats command.
So you can see that the mysql server was using ... mega on startup.
To recap what we did in this course, we first used
the docker container top command to list all the processes that are running in a single container.
Then we use the inspect command. In container inspection, we can actually see how the container was run, what was run with that container, and the environment and options that existed when it was started. Next, container stats, which is sort of a real-time updated view to see all the containers and the resources they're using while running.
That's all for this video, but see you soon for the next one.