Skip to content

Commit 0658ba7

Browse files
author
Misty Stanley-Jones
authored
Merge pull request docker#622 from mstanleyjones/add_info_about_docker_log
Add info about using docker logs
2 parents e341bee + 7d099ea commit 0658ba7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

_data/toc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ toc:
155155
title: Run a local registry mirror
156156
- sectiontitle: Logging
157157
section:
158+
- path: /engine/admin/logging/view_container_logs/
159+
title: View a container's logs
158160
- path: /engine/admin/logging/overview/
159161
title: Configuring Logging Drivers
160162
- path: /engine/admin/logging/log_tags/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
description: How to write to and view a container's logs
3+
keywords: docker, logging
4+
title: View a container's logs
5+
---
6+
7+
The `docker logs` command shows information logged by a running container. The
8+
information that is logged and the format of the log depends almost entirely on
9+
the container's endpoint command.
10+
11+
By default, `docker logs` shows the command's output just as it would appear if
12+
you ran the command interactively in a terminal. UNIX and Linux commands
13+
typically open three I/O streams when they run, called `STDIN`, `STDOUT`, and
14+
`STDERR`. `STDIN` is the commmand's input stream, which may include input from
15+
the keyboard or input from another command. `STDOUT` is usually a command's
16+
normal output, and `STDERR` is typically used to output error messages. By
17+
default, `docker logs` shows the command's `STDOUT` and `STDERR`. To read more
18+
about I/O and Linux, see the
19+
[Linux Documentation Project article on I/O redirection](http://www.tldp.org/LDP/abs/html/io-redirection.html)
20+
21+
In some cases, `docker logs` may not show useful information unless you take
22+
additional steps.
23+
24+
- If you use a [logging driver](overview.md) which sends logs to a file, an
25+
external host, a database, or another logging back-end, `docker logs` may not
26+
show useful information.
27+
28+
- If your image runs a non-interactive process such as a web server or a
29+
database, that application may send its output to log files instead of `STDOUT`
30+
and `STDERR`.
31+
32+
In the first case, your logs are processed in other ways and you may choose not
33+
to use `docker logs`. In the second case, the official `nginx` image shows one
34+
workaround, and the official Apache `httpd` image shows another.
35+
36+
The official `nginx` image creates a symbolic link from
37+
`/var/log/nginx/access.log` to `/dev/stdout`, and creates another symbolic link
38+
from `/var/log/nginx/error.log` to `/dev/stderr`, overwriting the previous
39+
devices in the process. See the
40+
[Dockerfile](https://github.com/nginxinc/docker-nginx/blob/8921999083def7ba43a06fabd5f80e4406651353/mainline/jessie/Dockerfile#L21-L23).
41+
42+
The official `httpd` driver changes the `httpd` application's configuration to
43+
write its normal output directly to `/proc/self/fd/1` (which is `STDOUT`) and
44+
its errors to `/proc/self/fd/2` (which is `STDERR`). See the
45+
[Dockerfile](https://github.com/docker-library/httpd/blob/b13054c7de5c74bbaa6d595dbe38969e6d4f860c/2.2/Dockerfile#L72-L75).
46+
47+
## Next steps
48+
49+
- Learn about using custom [logging drivers](overview.md).
50+
- Learn about writing a [Dockerfile](../reference/builder.md).

0 commit comments

Comments
 (0)