20241018 ◎

The higher dose of steroids prevents me from sleeping. I feel strange…

Logs in Docker

docker logs

docker container logs | Docker Docs

I can use the docker logs comamnd to fetch logs from a container. As I recall, the --follow, -f option and the --timestamps, -t option are frequently used together (by my colleagues).

For example, this command starts putting logs with timestamps to stdout.

docker logs --follow --timestamps container_name

I tried that with my Mastodon instance, but I got too many logs running through the display. It looks promising to get a specific number of logs instead.

~/mastodon$ docker logs --tail 5 sidekiq
2024-10-19T05:06:16.265Z pid=7 tid=2pdr INFO: queueing Scheduler::IndexingScheduler (indexing_scheduler)
2024-10-19T05:06:16.267Z pid=7 tid=kf2r class=Scheduler::IndexingScheduler jid=69d8e310d759d0de7eeee6d4 INFO: start
2024-10-19T05:06:16.270Z pid=7 tid=kf2r class=Scheduler::IndexingScheduler jid=69d8e310d759d0de7eeee6d4 elapsed=0.003 INFO: done
2024-10-19T05:06:49.638Z pid=7 tid=j30f class=ActivityPub::ProcessingWorker jid=24ef37eaf59d4b36cb798998 INFO: start
2024-10-19T05:06:49.645Z pid=7 tid=j30f class=ActivityPub::ProcessingWorker jid=24ef37eaf59d4b36cb798998 elapsed=0.007 INFO: done

~/mastodon$ docker logs -n 5 web
I, [2024-10-19T05:05:58.181290 #20]  INFO -- : [22b68e66-55ac-4090-a468-a143b7fd4e2a] method=POST path=/inbox format=html control
ler=ActivityPub::InboxesController action=create status=202 allocations=10643 duration=14.30 view=0.00 db=1.06 key=https://bgme.m
e/users/smilemonkey#main-key
I, [2024-10-19T05:06:11.645354 #12]  INFO -- : [d42fc1e8-6e65-42d7-9a68-e19a8fc595d0] method=HEAD path=/health format=*/* control
ler=HealthController action=show status=200 allocations=96 duration=0.97 view=0.80 db=0.00
I, [2024-10-19T05:06:41.781214 #20]  INFO -- : [0c4c1830-8c23-468c-916a-861919fec301] method=HEAD path=/health format=*/* control
ler=HealthController action=show status=200 allocations=95 duration=0.42 view=0.28 db=0.00
I, [2024-10-19T05:06:49.640489 #12]  INFO -- : [67b7012a-7fa3-44e2-9c2f-cc5af62ae457] method=POST path=/inbox format=*/* controll
er=ActivityPub::InboxesController action=create status=202 allocations=17592 duration=32.14 view=0.00 db=2.75 key=https://onsen-m
usume.fun/users/8l6kpzosrf#main-key
I, [2024-10-19T05:07:11.906894 #12]  INFO -- : [865b3dc9-b120-439d-b609-38a24d359c79] method=HEAD path=/health format=*/* control
ler=HealthController action=show status=200 allocations=95 duration=0.33 view=0.19 db=0.00

The problem with this approach is that when containers stop accidentally, and I want to troubleshoot, logs cannot be retrieved from the containers with this command because it is designed to show information logged by a running container.

json-file and its store location

I got this in my MacBook.

$ docker inspect --format='{{.HostConfig.LogConfig.Type}}' cbd206ed09ca  # container id
json-file

Configure logging drivers | Docker Docs

As a default, Docker uses the json-file logging driver, which caches container logs as JSON internally.

JSON file logging driver | Docker Docs

By default, Docker captures the standard output (and standard error) of all your containers, and writes them in files using the JSON format. The JSON format annotates each line with its origin (stdout or stderr) and its timestamp. Each log file contains information about only one container.

However, it seems the log file is not directly accessible when using Docker Desktop

Where are Docker Logs Stored? - Docker Logs Location | SigNoz

Direct Docker Engine installation is not supported on MacOS. However, you can use Docker on macOS through Docker Desktop.

To access individual Docker container logs on Docker Desktop, from the Docker Desktop UI, select the container of choice and click on the Logs section:

As I browsed some web pages (and some interactions with LLM)… When I'm using Docker Desktop, Docker is running inside a virtual machine, and the host filesystem does not have direct access to the container logs. The only options I have is the Docker Desktop itself, or docker logs <container-name>.

Possible solutions with other logging drivers

There are many kinds of logging drivers, and from my understanding, they are designed to route logs to external services, so that logs can be checked independently.

Some are

Google Cloud Logging driver

The Google Cloud Logging driver sends container logs to Google Cloud Logging Logging.

Amazon CloudWatch Logs logging driver

The awslogs logging driver sends container logs to Amazon CloudWatch Logs. Log entries can be retrieved through the AWS Management Console or the AWS SDKs and Command Line Tools.

Because I don't want to complicate the system components of my Mastodon server, I'll skip leveraging these options.


Sushi bowl 800 Lemonade 200 Chips 200 Pocky 200 Yogurt 150 Mashed potatoes 150

Total 1700 kcal


MUST:

TODO:


index 20241017 20241019