We earn commission when you buy through affiliate links.
This does not influence our reviews or recommendations.Learn more.
So lets get started.
Though do note here that the above command is only functional for containers that are started with thejson-fileorjournaldlogging driver.
This is achieved using JSON File logging driver orjson-file.
These logs are by default stored at container-specific locations under/var/lib/dockerfilesystem.
you’re able to use–followor-fflag to follow the log output.
This allows you to monitor new updates in the log stream from continuouslySTDOUTandSTDERR.
By default, this flag assumesallas an argument that shows the complete log stream.
The–sinceoption shows only the container logs generated after a given date.
you could combine the–sinceoption with either or both of the–followor–tailoptions.
In the above example, logs since only 2 minutes are shown wherenostalgic_wescoffis the auto-generated name assigned for thenginxcontainer.
In the above example, all logs before 1 hour 30 minutes are shown.
If you need Docker to explicitly prefix its timestamps in the output, use–timestampsor-tflag.
As a simple example, we can combine–tailflag with–sinceto get more restricted output.
This can work with other flags as well.
Utilities likegrep,head,tailetc.
can be piped todocker logsoutput for more advanced operations.
Do note here that we need to redirect log streams to provide single piped input forgrepusing2>&1.
Dockeris a versatile platform that offers numerous features to administer its environment.
Managing logs for a system is one of the essential skills which every system administrator should know.
Managing logs in Docker is easy once you know the available command and possible flags as per your requirements.
For further read on Docker and its functionalities, refer to Dockersdocumentation.