Are you having trouble accessing the Docker service logs of a Python application you deployed or find that the service logs are not working correctly, or not showing up at all?
Docker service logs play a vital role in helping one troubleshoot the problem. But when one of the main troubleshooting methods is not working, it can frustrate the developer. Trying to fix this problem can be quite a hassle.
This problem can be reproduced when creating a service running across multiple nodes. There are various solutions to the logs not being produced or shown.
You can try logging in using a command, or you might redirect your applications differently. There can be various reasons why you might be facing this problem.
This article explored nine ways you can fix your Docker service logs that are not showing or working.
Table of Contents
9 Fixes for Docker Service Logs Not Working or Showing
1. Docker Service Status
With a daemon-based design, Docker connects through its CLI to an ongoing process that runs independently on your computer or a distant host. In most cases, if the daemon stops, neither CLI commands nor your containers will function.
It is due to the reason mentioned above that it is important first to check and ensure that the Docker is active before moving on to the remainder of the troubleshooting steps.
One way to check that the docker service is running is by running the following command:
systemctl status docker
After running the command, look at the information under “Active.” Your containers should be active and running if you see the words “active (running)” in green color, which indicates that Docker is active.
If it is not active, it can be seen from the CLI. The CLI will show the words “inactive” on the interface. To start Docker again, simply run the following command:
systemctl start docker
Now, the above command only works if your Docker is not running or active. But upon running the first command mentioned here, you see that it shows the word “failed” in red, meaning there is some error which is why it is not starting.
One way to check why the service failed is to explore the startup logs for an answer. You can also start it in debugging mode to check what the problem might be by running the following command:
dockerd --debug
2. Docker Log Driver
To make getting information from running containers and services easier, Docker comes with various logging techniques.
Logging drivers are the term for these devices. Unless you specify a container to use a different logging driver or “log-driver” each Docker daemon has a default logging driver that each container uses.
Check if the Docker log driver is configured to the proper value. The log driver is the one that determines the containers’ output. You might be unable to view Docker service logs if the log driver is configured to an invalid or unsupported value.
JSON-file is the standard log driver, but alternative choices, like syslog and journald, are also available. You can use the following command to examine the log driver:
docker info | grep Logging
Another problem related to the logging driver can be its log level. The log level determines the level of detail in the Docker service logs.
A higher log level may result in excessively huge log files that soon consume all available disc space. Use the following command to check the log level:
docker info | grep 'Logging Driver'
3. Docker Container Logs
One of the ways to see what the problem can be is to start inspecting the log files of your individual containers.
You can run the following command to get the complete list of all your docker containers. This will help you in going through all the containers one by one.
docker container ls
When you get a list of your containers, you can run the following command to check the container log of that particular container:
docker logs [container_name]
In the above command, replace the [container_name] with the name of the container you want to inspect.
When you are going through these commands, it is important to note that if a container is not running, there will be no records for that container.
4. Docker Log File Location
Docker logs are, by default, kept in the file system of the host machine. The log files may be located differently depending on the operating system and Docker version.
For example, on Linux systems running Docker, the default location for Docker log files is /var/log/docker/, and the file names are in the format container_id.log.
On Windows systems running Docker, the default location for Docker log files is C:\ProgramData\Docker\containers\<container_id>\<container_id>-json.log, where <container_id> is the ID of the container.
To check exactly where log files are for a particular container, you can run the following command:
docker inspect --format='{{.LogPath}}' <container_name>
The path to the log file for the chosen container will be shown by this command. The log file’s contents can then be viewed using common file system utilities like cat or tail.
If any log files are present, you can inspect this directory. The Docker service may not effectively log if no log files are present.
5. Docker Configuration
The Docker configuration file specifies many settings, including network configuration, logging options, security settings, and more. It also controls how the Docker daemon functions.
The location of the Docker configuration file may vary depending on the operating system and the Docker version. Here are the most common locations:
- Linux: /etc/docker/daemon.json
- macOS: ~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/daemon.json
- Windows: C:\ProgramData\Docker\config\daemon.json
To ensure there are no problems or faults that might be preventing Docker service logs from appearing, you can verify the Docker configuration files.
6. Docker Version
You can also check your docker version to ensure it is updated. Older versions of Docker can cause logging problems; you can help eliminate this factor by updating the version.
You can run the following version to check the docker version:
docker version
To update your docker, you can visit the following official documentation.
7. Disk Space Issues
Docker might be unable to write logs to the disc if there is not enough available space on the host machine. Using the df command, check available disc space, delete any redundant files, or add more disc space as needed.
8. Docker Syslog Configuration
Instead of writing log messages to a file on the local file system, You can configure Docker to transmit them to a syslog daemon. This can be helpful when you wish to centralize log messages and make them simpler to manage.
It’s possible that the logs are being transmitted to syslog instead of the Docker log files if the Docker service logs are not appearing in the Docker log files. To make sure that the Docker logs are being written to the appropriate log files, check the syslog configuration.
9. Docker User Permission
Verify that the person operating the Docker service is authorized to write to the specified location for the log file. If not, you can modify the ownership of the log file directory or allow the user permission.
Conclusion
As a developer, it is completely understandable to feel frustrated when trivial things such as Docker service logs are not working for you. This is why we created this guide to help you solve this problem and get back to work in no time!
Lastly, let us know in the comments:
- Were you also unable to fix your Docker service log issues?
- Did any of the solutions work for you?
- Is there any missed solution you would like to add to the list?
Feel free to share this article with any of your fellow developers who are encountering issues reading their Docker service logs that aren’t showing up or generally working correctly!