Clear logs in native Docker on Mac

I want to get rid of huge container log files on my docker env.

I have problem finding them when running native Docker on a Mac. I am not using docker-machine (virtualbox) thing. My docker version is 1.13.1.

When I do

docker inspect <container-name>

I see there is

"LogPath": "/var/lib/docker/containers/<container-id>/<container-id>-json.log

But there is not even directory /var/lib/docker on my mac (host).

I have also looked in

~/Library/Containers/com.docker.docker/

but didn't find any container specific loggings there.

I could use tail, but it is not that convenient always to me.

So the question is, how can I clear the log files of my containers on my native Docker Mac environment.


Docker daemon runs in a separate VM, so in order to clear logs you should do the following steps:


First, you can find the log path inside the VM, with:

docker inspect --format='{{.LogPath}}' NAME|ID


You can connect to the VM with screen

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty


Here you can simply use output redirection to clear the log

> /var/lib/docker/containers/CONTAINER_ID/CONTAINER_ID-json.log


And finally you can detach the screen with hitting Control+a d


I added the following to my bash_profile. it gets the logpath for the docker container, opens a screen to the docker machine and deletes the logfile.

clearDockerLog(){
dockerLogFile=$(docker inspect $1 | grep -G '\"LogPath\": \"*\"' | sed -e 's/.*\"LogPath\": \"//g' | sed -e 's/\",//g')
rmCommand="rm $dockerLogFile"
screen -d -m -S dockerlogdelete ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
screen -S dockerlogdelete -p 0 -X stuff $"$rmCommand"
screen -S dockerlogdelete -p 0 -X stuff $'\n'
screen -S dockerlogdelete -X quit
}

use as follows:

clearDockerLog <container_name>