Clear logs in native Docker on Mac

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

I have a problem finding them when running my own Docker on Mac. I do not use docker-machine (virtualbox) thing. My docker version is 1.13.1.

When i do

docker inspect <container-name> 

I see that there is

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

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

I also looked

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

but did not find any specific containers there.

I could use the tail, but this is not always convenient for me.

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

+5
source share
2 answers

The Docker daemon runs in a separate virtual machine, so to clear the logs you need to do the following:


First you can find the log path inside the virtual machine:

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


You can connect to a virtual machine using 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 disconnect the screen by pressing Control + a d

+3
source

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

 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 the following:

 clearDockerLog <container_name> 
+1
source

Source: https://habr.com/ru/post/1264869/


All Articles