Listing items
Listing items is part of normal everyday operations are used to check things like containers running, container versions etc.
Listing containers
To list containers one would use the ps command.
docker ps
This command would provide and output similar to the below
In the screenshot you can see the container id, image version, command, created date, status , ports and assigned name is displayed. To make things similar the container name can be used when commands are issued to the environment that addresses a container directly.
Listing images
Listing images provides a definitive listing of all container images present on the local machine. This may or may not be limited to the current versions required by the running containers.
docker images
The output of the docker images command will supply you with the list of images as well as other relevant information such as their tag’s, image id, repository etc. Please note that these are quite important when raising a support incident under the support packages available.
Listing logs
Listing the logs for a container is very helpful when troubleshooting items. It will in many cases give direct information that will assist in resolving any issues.
To list the logs for a particular container the structure would be “docker logs <container_name>”. However it is important to note that sometimes the container may have been running for an extremely long time and it would be recommended to limit the log volume output to a specific number of lines using the “--tail” operator. If an error is intermittent, it may be required to “follow” the log similar to the way the normal tail command is used in Linux. Examples of various types are listed below.
#Base command
docker logs <container_name>
e.g. docker logs wazuh
#Limiting log output to a number of lines (150)
docker logs --tail 150 <container_name>
e.g. docker logs --tail 150 wazuh
#Continue to follow the log
docker logs -f <container_name>
e.g. docker logs -f wazuh
#Continue to follow logs and limit initial number of lines from log (150)
docker logs -f --tail 150 <container_name>
e.g. docker logs -f --tail 150 wazuh
Combining the output with additional command line commands
In some cases it may be required to use additional commands to trim the output to narrow down the scope of the logs. Commands like grep can be very useful for this. Below is an example of grepping for errors
docker logs -f --tail 150 wazuh |grep -i error
The -i used will make the search case insensitive and will match as long as the letters match in the sequence specified. There are many other commands such as this that can be used. It would benefit the user greatly to become more versed in the Linux command line.