kgs
kgs

Reputation: 1864

How to use --since option with docker logs command

I want to look at last 1 hour of docker container log using docker logs --since option. Which value I should provide for --since parameter?

Upvotes: 38

Views: 97093

Answers (3)

joeytwiddle
joeytwiddle

Reputation: 31255

You may want logs from a specific date, but docker might not like your date's format.

In such cases, check whether the UNIX date command can parse it:

$ date -d "your date here"
Wed Oct  5 12:46:17 GMT 2022

If date's output looks right, then you can use date -I to produce a format that docker understands.

$ docker logs my_container --since "$(date -I -d "your date here")" | less -RX

Upvotes: 5

hackjutsu
hackjutsu

Reputation: 8922

Please refer to the Docker docs.

docker logs --since 1h

The --since option shows only the container logs generated after a given date. You can specify the date as an RFC 3339 date, a UNIX timestamp, or a Go duration string (e.g. 1m30s, 3h). Besides RFC3339 date format you may also use RFC3339Nano, 2006-01-02T15:04:05, 2006-01-02T15:04:05.999999999, 2006-01-02Z07:00, and 2006-01-02.

Upvotes: 27

user2915097
user2915097

Reputation: 32156

as the help says

--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes

I would do

docker logs mycontainer_or_id --since 60m

This syntax is correct according to my active container

Upvotes: 64

Related Questions