wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Docker container logs for quick troubleshooting

by | Jan 6, 2017

Docker enables easy deployment of applications inside containers and this makes it popular in hosting and development businesses. But proper management of the Docker system is essential to reap the benefits of this infrastructure setup.

A Docker container that always crashes, a host machine that doesn’t have enough space, an application that throws up errors – all these issues can cripple the effectiveness of using a Docker system for your business.

Relevance of logs in Docker management

A efficient Docker management service involves a wide range of activities – creating new containers, resource control, performance monitoring, error debugging, automating tasks, backup management, and so on.

Examining the log files is vital in troubleshooting errors and issues during Docker management. A typical Docker setup consists of multiple containers, each with a log file associated with it.

These log files store all the relevant information and updates related to that container. When a container crashes often or the application running in it gives out random errors, these logs shed some light into what’s actually the cause.

In addition to container logs, there are service logs and host machine logs. Today, we’ll see how to access these various logs in a Docker system.

[ Use your time to build your business. We’ll take care of your customers. Hire Our Hosting Support Specialists at $9.99/hr. ]

How to access Docker container logs

To investigate the issues related to a Docker container, the container logs are useful. The logs associated with each container can be reviewed using these simple steps:

1. Connect to the Docker machine

Access the host machine in which the Docker containers are hosted, from the shell. You can use the ‘ssh’ tool from the command line interface to do that.

2. Identify the container ID

First we need to identify the container for which the logs are to be checked. You can list the whole containers in the machine using ‘docker ps’ command.

Choose the container ID of the one you need to check, from the list. The container ID associated with the application name (eg: WordPress), can be looked upon easily in this list.

 

docker container logs list

List docker containers

Suppose we need to examine the logs for the WordPress container. We can see that the container ID is ‘679facd4ee38’, from this list.

3. Examine the container logs

To view the logs for the WordPress container, use the command ‘docker logs [ID]’ where [ID] is the container ID.

 

examine docker container logs

Examine the logs for the selected container

 

Every Docker container has a folder “/var/lib/docker/containers/container-id” in the host machine, which contains the log file ‘container-id-json.log’. ‘json.log‘ is the default logging setup and it contains all the updates and access details to that container.

The contents of this log file are displayed using ‘docker logs’ command. The path to this container log file can be identified using the command ‘docker inspect [ID]‘ where [ID] is the container ID.

 

docker container logs path

Obtain the Log path for the container

 

Any information or message that is displayed to the container’s standard output/error will be logged in this json.log file, which can be retrieved using ‘docker logs‘ command.

 

docker container log json file

json log for the container

 

4. Investigate the Docker container logs

Memory errors, resource shortages, kernel problems, malicious attempts, attacks, etc. can be detected and investigated with the help of container logs.

Certain applications have their own extended log files, which are helpful in identifying and debugging the application related errors. Once the cause of the errors are identified, it is easy to fix them without delay.

[ You don’t have to lose your sleep to keep your customers happy. Our Hosting Support Specialists cover your servers and support your customers 24/7 at just $9.99/hour. ]

How to access Docker service logs

In a Docker host machine, the ‘docker’ service should run fine, for the containers to work. But the Docker service can fail due to human or technical errors that range from memory issues to file errors.

Docker service related status updates and errors can be examined using the Docker service logs in the host. If the host machine OS supports ‘systemd’, then the Docker daemon logs can be examined using the command:

journalctl -fu docker.service

‘journald’ is the logging service which comes with systemd. This command will display all the Docker service messages as shown:

docker container logs docker service

Docker service logs

How to access Docker machine logs

The Docker host machine specific logs can be viewed using the ‘dmesg‘ utility. Dmesg gives the kernel logs and device driver messages to the command line.

Any issues related to host machine, such as kernel or memory errors, can be debugged using ‘dmesg’ tool:

docker container logs host machine

Docker host machine logs

External logging for Docker management

Docker containers do not store data in a persistent manner. So, any files or data saved in the container will be lost upon a restart of that container.

As a result, any logging setup that we do for applications hosted in Docker containers, should be done external to the container and not saved in a file in it.

This external logging for applications can be done with the help of ‘syslog‘ facility. An external server can be configured for storing the logs.

The logs would be transferred to the syslogd server via network. While starting a container, we just have to mention the IP address of the syslogs server as:

docker run --log-driver=syslog --log-opt syslog-address=tcp://IPaddress:port

Another option is to use ‘data volumes‘ for storing logs. Using data volumes, you can map a directory in the container to an external directory in the host machine.

The data stored in these external data volumes would be secure even after container restarts. It is possible to configure centralized logs for all containers using data volumes.

To summarize..

Here, we’ve seen the different log files associated with Docker containers and how to access each of them for quick troubleshooting in docker management.

The type of logs that need to be enabled in the containers and the extent of logging are determined based on their business purpose.

Log files are set to rotate periodically and are not stored within containers. This helps to avoid disk space from being used up, as that can lead to crashes.

If you’d like to know how to manage your Docker resources efficiently for your business purpose, we’d be happy to talk to you.

 

STOP SPENDING TIME ON SUPPORT!

Do you spend all day answering technical support queries?

Wish you had more time to focus on your business? Let us help you.

We free up your time by taking care of your customers and servers. Our engineers monitor your servers 24/7, and support your customers over help desk, live chat and phone.

HIRE SUPPORT SPECIALISTS AT $9.99/HR

Bobcares provides Outsourced Web Hosting Support and Outsourced Server Management for online businesses. Our services include 24/7 server support, help desk support, live chat support and phone support.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags