truncate docker container log

sometimes you just want to clear logs of a docker container.
For instance, I’m running dnsmasq in a docker container and I’m troubleshooting raspberry PI PXE boot (yes to run ESXi-ARM stateless…)
And the dnsmasq is serving my homelab its domain.
Then it can be an annoyance when you run docker logs <container name> seeing all the log entries since the container started.
And you just want to start with a clean slate.

It is the way

Yes, there is a way. And when you google you’ll find more blog posts giving you the solution. Which is

pi@raspberrypi~ $ sudo docker inspect --format='{{.LogPath}}' <container name>
pi@raspberrypi~ $ sudo truncate -s 0 <path presented by previous command>

And it works great… but… typing 2 lines of code… copy / pasting the log path in the second command.. way too dificult 🙂
So what do you think abou this ?

pi@taspberrypi~$ sudo  truncate -s 0  $(docker inspect --format='{{.LogPath}}' <container name>)

Yes, it will erase all logging, but that is the purpose of this whole excercise.

Addendum

If the one-liner isn’t helping, how about creating a small script just for one purpose alone…. What if you could do something like

pi@raspberrypi~$ truncate-log dnsmasq

To truncate the docker logs of the dnsmasq docker container. How ? Well easy.
Just create a new file in /usr/local/bin

pi@raspberrypi~$ nano /usr/local/bin/truncate-log

and copy / paste this content into the file

#!/bin/sh
CONTAINER=$1
truncate -s 0 $(docker inspect --format='{{.LogPath}}' $CONTAINER)

After saving the file. (Ctrl-x), add the execution bit

pi@raspberrypi~$ chmod +x /usr/local/bin/truncate-log

And voila, the next time you need to truncate a docker container log, you just type truncate-log <docker container name>

rPI adventures bits III

Some of the default installations have a graphic desktop. But, when you use your rPIs headless, what’s the point of these interfaces.
Of course you can remove them, but you can also use remote connections.
And then you have by default VNC, for which you need to start the service first.
But a RDP service, wouldn’t that be usefull, and is it possible ?
Yes it is.

XRDP

It is called xrdp.
xrdp is an open-source remote desktop service for linux. And ues, you can run it on a rPI. To find more inf about xrdp check out their site http://xrdp.org/

Install XRDP

To install xrdp on a rpi run the following steps. (assuming you are running raspion OS

  • login to the rPI or with a terminal or via ssh
  • update software
pi@raspberrypi:~$ sudo apt update
pi@raspberrypi:~$ sudo apt full-upgrade
  • install xrdp
pi@raspberrypi:~$ sudo apt-get install xrdp
  • start a RDP client and connect to the rPI

And easy as pi 🙂

Purpose

Well, for me it is a stepping stone into my homelab.
I have rPI for running dns,tftp,dhcp,samba,http,ntp, unifi controller services in docker containers.
With this setup I can control my homelab from this stepping stone. And also acces the IPMI interface of my supermicro server, hosting my vSphere homelab.

rPI adventures bits II

ssh access on first boot

I’m using my rPI headless. Meaning no monitor, mouse and keyboard. Just an ethernet connection.
And that is great, but then you need to have ssh access.. and by default that is not running.
There are some small steps to have ssh running on boot, these are the steps
(assumption is that your network has a DHCP service running)

  1. insert SD card into your Windows / MacOS / Linux system
  2. create a file named ‘ssh’ on the root partition.
  3. Insert the SD card into the rPI
  4. boot the rPI
  5. check your DHCP service log for a new created IP lease
  6. SSH to the IP found in the previous step
    Default username: pi, password: raspberry

rPI adventures bits I

Yes, I’ve stept into the realm of raspberry pi.
Adding this to my homelab setup.

For now I’ll just scribble some stuff I need to remember. Later on I’ll write detailed blogs about the setup of my homelab.

Temperature check

rPI’s are getting hot. Especially the rpi 4B+.
To check it’s core temp you can run the following command

root@raspberrypi:~# /opt/vc/bin/vcgencmd measure_temp

To make life easier I created a small script called ‘temp’ and placed it in /usr/local/bin.

#!/bin/sh
/opt/vc/bin/vcgencmd measure_temp

Also make sure it is executable.

chmod +x /usr/local/bin/temp

Now you can check the temp by running the command temp.

root@raspberrypi:~# temp
temp=47.8'C
%d bloggers like this: