- [Speaker] A useful command for analyzing docker services,
even containers and images at a low level,
is the 'docker inspect' command.
Let's take a look at how we can use 'docker inspect'
to analyze a service at the lowest level.
If you type 'man docker inspect',
you can get all sorts of detailed information
that shows you how to use the 'docker inspect' command
to pull out specific JSON values from the JSON array
that represents the container objects.
Besides services and containers,
'docker inspect' can also be used to analyze
images, volumes, networks, nodes, and tasks,
at the lowest level.
For example, if we do a 'docker service ls',
we have our webapp service running,
let's go ahead and do a 'docker inspect' on 'webapp1'.
And I'm going to pipe this to 'more',
because I'll tell you the output
is going to be rather lengthy,
and this tells us all sorts of detailed information
about the webapps service.
So here we have the name of the service,
in this case is webapp,
we have the exact image name,
which is "nginx:latest",
and if we scroll on down,
you can see we have the number of replicas for this service,
six replicas in this case,
as well a number of advanced configuration details
for the service.
So that's 'docker inspect', using it against a service.
Of course you could also pipe the output here,
for example to 'grep'.
So we can see "Replicas" are just six in this case,
by using 'grep' to pull out that output.
And of course we can also use 'docker inspect'
on other things like containers.
If we clear the screen,
let's do a 'docker service ls',
so we have our service,
let's do a 'docker ps',
so there are the containers or tasks that are running,
based on this service.
And so if we do a 'docker inspect' and we select
one of the container IDs,
for example this one starts with "cd0",
we'll just type 'cd0' here,
we'll pipe that to 'more',
and here we get all sorts of detailed low-level information
about this specific container.
For example, if we scroll on down,
if we wanted to find out the IP address
for just this one container,
we could do it by utilizing 'docker inspect'.
For example, here's the host name for this container.
You can see that this container
is part of the service called webapp.
And down here, you can see the IP address
for the container itself:
its default gateway, Subnet mask, and more.
And of course you can always 'grep' out
that sort of information,
here we'll just 'grep IPAddress',
and there we get the same IP address information
without combing through the file.
So that's how to use 'docker inspect'
to analyze services in Docker Swarm.