Docker for Mac – how to empty logfile

When testing a docker app locally, it’s often useful to have a fresh logfile to output. With Docker-for-Mac it’s a bit more difficult due to the VM, but you can use the code below to do this successfully (example is for docker-compose):

SERVICE=docker-compose-service-name
 
LOGPATH=$(docker inspect --format='{{.LogPath}}' $(docker-compose ps -q $SERVICE))
 
docker run -it --rm --privileged --pid=host alpine:latest nsenter -t 1 -m -u -n -i -- truncate -s0 $LOGPATH

Leave a Reply