github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/logs.md (about) 1 --- 2 title: "logs" 3 description: "The logs command description and usage" 4 keywords: "logs, retrieve, docker" 5 --- 6 7 <!-- This file is maintained within the docker/cli GitHub 8 repository at https://github.com/docker/cli/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # logs 17 18 ```markdown 19 Usage: docker logs [OPTIONS] CONTAINER 20 21 Fetch the logs of a container 22 23 Options: 24 --details Show extra details provided to logs 25 -f, --follow Follow log output 26 --help Print usage 27 --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes) 28 --until string Show logs before timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes) 29 --tail string Number of lines to show from the end of the logs (default "all") 30 -t, --timestamps Show timestamps 31 ``` 32 33 ## Description 34 35 The `docker logs` command batch-retrieves logs present at the time of execution. 36 37 > **Note**: this command is only functional for containers that are started with 38 > the `json-file` or `journald` logging driver. 39 40 For more information about selecting and configuring logging drivers, refer to 41 [Configure logging drivers](https://docs.docker.com/config/containers/logging/configure/). 42 43 The `docker logs --follow` command will continue streaming the new output from 44 the container's `STDOUT` and `STDERR`. 45 46 Passing a negative number or a non-integer to `--tail` is invalid and the 47 value is set to `all` in that case. 48 49 The `docker logs --timestamps` command will add an [RFC3339Nano timestamp](https://golang.org/pkg/time/#pkg-constants) 50 , for example `2014-09-16T06:17:46.000000000Z`, to each 51 log entry. To ensure that the timestamps are aligned the 52 nano-second part of the timestamp will be padded with zero when necessary. 53 54 The `docker logs --details` command will add on extra attributes, such as 55 environment variables and labels, provided to `--log-opt` when creating the 56 container. 57 58 The `--since` option shows only the container logs generated after 59 a given date. You can specify the date as an RFC 3339 date, a UNIX 60 timestamp, or a Go duration string (e.g. `1m30s`, `3h`). Besides RFC3339 date 61 format you may also use RFC3339Nano, `2006-01-02T15:04:05`, 62 `2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local 63 timezone on the client will be used if you do not provide either a `Z` or a 64 `+-00:00` timezone offset at the end of the timestamp. When providing Unix 65 timestamps enter seconds[.nanoseconds], where seconds is the number of seconds 66 that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap 67 seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a 68 fraction of a second no more than nine digits long. You can combine the 69 `--since` option with either or both of the `--follow` or `--tail` options. 70 71 ## Examples 72 73 ### Retrieve logs until a specific point in time 74 75 In order to retrieve logs before a specific point in time, run: 76 77 ```bash 78 $ docker run --name test -d busybox sh -c "while true; do $(echo date); sleep 1; done" 79 $ date 80 Tue 14 Nov 2017 16:40:00 CET 81 $ docker logs -f --until=2s 82 Tue 14 Nov 2017 16:40:00 CET 83 Tue 14 Nov 2017 16:40:01 CET 84 Tue 14 Nov 2017 16:40:02 CET 85 ```