|
| 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