# 检查Docker日志

当使用 `docker logs <containername>` 方法检查容器日志时候，就会发现日志实在太多导致无法查看。

虽然Docker官方文档说docker日志是输出到 `STDOUT` 和 `STDERR` ，但是我尝试重定向日志还是失败:

> 假设这里的容器名字是 `mycontainer`

```
docker logs mycontainer 2>&1 > mycontainer.log
```

实际上可以直接检查容器日志文件，首先查看容器日志在哪里：

```
docker inspect --format='{{.LogPath}}' mycontainer
```

可以看看到容器日志是 `/var/lib/docker/containers/6807413c514e8a401f60e4581d80b64a84afefd023e3fd2faf30009ce2eb6a0e/6807413c514e8a401f60e4581d80b64a84afefd023e3fd2faf30009ce2eb6a0e-json.log`

另外，也可以实时检查日志

```
tail -f `docker inspect --format='{{.LogPath}}' mycontainer
```

## 参考

* [how to redirect docker logs to a single file?](https://stackoverflow.com/questions/41144589/how-to-redirect-docker-logs-to-a-single-file/41147654#41147654)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/virtual/docker/using_docker/check_docker_log.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
