One of the most challenging aspects of containers, especially when you’re first getting started, is troubleshooting them. Unlike VMs, which you can easily inspect to determine whether they’re functioning properly, the only way to really tell what’s going on inside a container (besides reading the code) is by looking at logs. Luckily, there are several tools that you can use to view and filter these logs so that you have an easier time tracking down problems with your applications in production.
The benefits of using Logentries
Logentries provide several benefits for viewing Docker logs. The first is the ability to see all of your logs in one place. This can be helpful when you’re trying to troubleshoot a problem, as you can quickly scan through all of the logs to see if anything stands out. You also have the option to filter or search based on specific strings, which makes it easy to find what you’re looking for.
The second benefit is that we display JSON logs in their raw form so that you don’t need any sort of advanced knowledge about parsing log files or writing custom code to make sense of them.
Docker container log file location
Docker containers use the standard syslog logging driver, which outputs container logs to a file. By default, this file is located at /var/lib/docker/containers/. However, the location can be changed by adding the –log-driver and –log-opt options to the docker run command.
To view logs for a specific container, use the docker logs command. This command accepts the same options as the docker run command. For example, if you want to tail log output from container 5f3e7b84c2e4 on the server named server1 in terminal 1, type:
$ docker logs -f -t 5f3e7b84c2e4
The key fields when diagnosing an issue
There are a few key fields you should look at when diagnosing an issue with a container: the status, the name, the image, the command, and the created field. The status field will tell you whether the container is running or not. The name field can help you identify which container is having issues. The image field tells you what image the container is using. The command field shows you the command that was used to start the container. The created field tells you when the container was created. If there is a time difference between when the container was started and when it stopped, then this could be why it’s in stopped state. For example, if the last run time for a container was 10 minutes ago but now it’s showing as stopped, then one of these things might have happened:
In some cases, logs from containers may not show up on your screen until they are manually rotated through.
Configuring Docker to forward logs to your account
In order to view your Docker logs, you first need to configure the logging driver. You can do this by adding the following line to your `/etc/docker/daemon.json` file: log-driver: syslog, log-opts: -f /dev/stdout } } After restarting Docker daemon with the new configuration, your containers’ logs will be forwarded to a syslog endpoint of your choice (e.g., Redis or Google Cloud).
Visualizing your data with Kibana Dashboards
If you’re using the ELK stack for logging, then you know that Kibana is a powerful tool for visualizing your data. But did you know that you can also use Kibana to troubleshoot your Docker containers? By creating a dashboard specifically for your containers, you can quickly and easily see what’s going on inside them. Here’s how 1) Create a new Dashboard by clicking the + sign in the upper left corner of Kibana and choosing New Dashboard. Give it a name like Docker Container Troubleshooting or something similar.