10

I'm trying to pipe json logs from docker into jq. It works fine if I use:

docker logs container_id 2>&1 | jq '.'

But, if I try to tail it, it gets stuck.

docker logs -f container_id 2>&1 | jq '.'

While tailing by itself does work:

docker logs -f container_id 2>&1

What am I missing here?

eran
  • 261
  • 2
    AFAIK the command docker logs container_id shows plain text data so it is useless to redirect it to jq. The log files are indeed internally stored as json and json files. The path to log file for a particular container can be retrieved docker inspect container_id | grep LogPath. And the json can be continuously showed: tail -f logfile | jq . – Zaboj Campula Jan 30 '17 at 18:49

1 Answers1

3

Try adding --unbuffered --stream so your command becomes

docker logs -f container_id 2>&1 | jq --unbuffered --stream '.'

It seems many other people have had a similar problem. Here are some bug reports on jq about this topic

Ben XO
  • 334