- [Instructor] Whether you need to record what's happening
in your data center for compliance
or simply to have something useful to use
when the unexpected happens,
it's important to have logging properly configured
in a production Docker infrastructure.
Now there's two different places to configure Docker logging
that you need to be aware of.
First, there's the default log type for each Docker daemon.
Second, you can configure per-container log types
that can override the default Docker daemon log.
Now let's go over to the command line
and configure Docker logging.
To find out what type of logging
you have configured currently,
you can use the docker info command.
We're just going to grep 'Logging Driver' here,
and that tells us exactly that we have json-file
configured as our logging driver for the Docker daemon.
So that's for the entire Docker node or host.
And that's actually the default, json-file.
Now there's a number of different other
Docker logging drivers that you can configure.
To change the default logging type,
you actually need to go into etc/docker
and you need to be root to do it.
And it's in here that you can create a file
called daemon.json, and that's where you would configure
the overrides for the default Docker daemon process,
and one of those overrides can be to change
the logging driver.
For example, you could change from
the json-file driver, the default,
to syslog, CloudWatch, Google Cloud, and even Splunk
for your logging driver.
So that's for the Docker daemon process.
Now to view the log file for a specific container,
you actually use the docker logs command.
And with that, you specify the container name.
So if we do a docker ps,
we can find the name of the container here.
So let's do docker logs.
And then we can just type in the first few characters
of a container ID.
For example, the very first container ID at the top is a1d.
I'll enter that there,
and we get the log file for that Docker container.
So you can see what that Docker container has been doing.
Now if you want to start a new container
and change the container logging driver from the default,
or use a different default logging driver
from what's configured on your Docker server,
you do docker space run,
and then you use the log-driver option
to specify the log driver
that will be used with this container only.
And then every log driver has its own set of parameters
that you need to provide,
and those are typically provided with the log-opt,
and then after that in the case syslog,
you need to provide the syslog address
for the syslog server that these logs will be sent to.
And finally, we'll enter the name of the container
that we're going to execute with the custom log driver.
So that container started.
It stopped immediately
because we didn't make it interactive,
but the logs for that container would be sent
to the syslog server.
So that's an example of customizing the log driver
for a specific container, and then before that,
you saw how to change the log driver
for the entire Docker daemon.