Home >Operation and Maintenance >Docker >How to check the log if docker fails to start

How to check the log if docker fails to start

WBOY
WBOYOriginal
2022-02-07 11:49:1822320browse

How to view logs after docker startup fails: 1. Use the inspect command to obtain the log address of the container. The syntax is "docker inspect --format container name"; 2. Use the cat command to view the log address found by the inspect command. The syntax is "cat log address".

How to check the log if docker fails to start

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.

How to check the log if docker fails to start

When using docker, the container may be started under some unknown circumstances, but the container will automatically exit after a few seconds. How to troubleshoot the problem at this time?

Usually encountering this situation is nothing more than a problem with the environment or application. Application problems can be debugged and solved locally, but environmental problems are more troublesome. At this time, we need to check the logs of the container to troubleshoot.

The example is as follows:

We can get the log address of the container through the following command

docker inspect --format '{{.LogPath}}' 97069f94437b

Then use the cat command to view the log found by the above command

cat /var/lib/docker/containers/97069f94437b86b50341f8253d85f426884315c3d027f7b7fa975751c7d8e18e/97069f94437b86b50341f8253d85f426884315c3d027f7b7fa975751c7d8e18e-json.log

Command explanation:

  • #docker inspect is used to obtain the metadata of the container/image. It contains the address of the container log. The above command only adds a --format parameter to filter out the log address.

  • There is a lot of information in docker inspect, you can execute the command to view it.

Of course, there is also the most direct and simple command

docker logs 97069f94437b

Recommended learning: "docker video tutorial"

The above is the detailed content of How to check the log if docker fails to start. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn