How to clean Docker container logs

2,416 views
Skip to first unread message

Sabzar Ahmad

unread,
Mar 28, 2016, 9:48:27 AM3/28/16
to docker-dev
HI ,

I am running the mobicents/restcomm image with the bellow command


docker run -d -e STATIC_ADDRESS="192.168.99.100" -e OUTBOUND_PROXY="10.10.222.85" --name=restcomm -e ENVCONFURL="https://raw.githubusercontent.com/RestComm/Restcomm-Docker/master/scripts/restcomm_env_locally.sh" -p 80:80 -p 443:443 -p 9990:9990 -p 5060:5060 -p 5061:5061 -p 5062:5062 -p 5063:5063 -p 5060:5060/udp -p 5083:5083/tcp  -p 5083:5083/udp -p 65000-65100:65000-65100/udp mobicents/restcomm:latest


When I run docker logs –f <container id> , A huge logs are getting displayed. These logs are taking huge space. I tried clean the container but I am not getting it. 

Could some one please check and let me know how can I clean docker container logs. Thanks in advance




Henrique Rosa

unread,
Mar 28, 2016, 1:56:40 PM3/28/16
to docker-dev
Hi Sabzar, 

The mobicents/restcomm repo is deprecated. You should pull your image from restcomm/restcomm instead.

I advise you to read the RestComm-Docker quick start guide, where it teaches you basic configuration like location of the logs.

For example, the following command specifies a host directory as a data volume where the RestComm logs will be contained:

docker run  -i -d --name=restcomm -v /var/log/restcomm/:/var/log/restcomm/ -e STATIC_ADDRESS="YOUR_ETHERNET_IP" -e ENVCONFURL="https://raw.githubusercontent.com/RestComm/Restcomm-Docker/master/scripts/restcomm_env_locally.sh" -p 80:80 -p 443:443 -p 9990:9990 -p 5060:5060 -p 5061:5061 -p 5062:5062 -p 5063:5063 -p 5060:5060/udp -p 65000-65050:65000-65050/udp restcomm/restcomm:latest

I hope this helps.

Regards , 
- H

Sebastiaan van Stijn

unread,
Mar 28, 2016, 2:51:59 PM3/28/16
to Henrique Rosa, docker-dev
When using the default (json file) logging, you can also configure docker to limit the size of the log file, and do rotation;

Also, when using "docker logs", you can use --tail to specify the number of lines to return,
or --since to show only new log-events after a given time/date;





--
You received this message because you are subscribed to the Google Groups "docker-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to docker-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sabzar Ahmad

unread,
Mar 29, 2016, 6:17:48 AM3/29/16
to docker-dev, henriq...@telestax.com
Thanks for reply,

I just want to know how can I delete restcomm container logs. The logs which gets displayed with the command (docker logs <container id>.
I know the use of command (docker logs <container id>). But I am not getting how to delete these logs.

Also I cannot see any suggestions related logs at RestComm-Docker quick start guide,



elefther...@telestax.com

unread,
Mar 29, 2016, 8:45:29 AM3/29/16
to docker-dev

Hi Sabzar, 
 As I can see from the earlier response from Sebastiaan (https://docs.docker.com/engine/admin/logging/overview/#json-file-options).
You can disable logging for docker container using . --log-driver=none.

B.R.

Sabzar Ahmad

unread,
Mar 30, 2016, 2:53:42 AM3/30/16
to docker-dev
Thanks B.R.

I don't want to Disable the logs. I just need to clean the old logs.

Muayyad AlSadi

unread,
Mar 30, 2016, 3:17:40 AM3/30/16
to Sabzar Ahmad, docker-dev

You can pass the logs to syslog or journald and both do log rotation out of the box


On Wed, Mar 30, 2016, 8:53 AM Sabzar Ahmad <sabza...@gmail.com> wrote:
Thanks B.R.

I don't want to Disable the logs. I just need to clean the old logs.

--

Edwin Hermans

unread,
Mar 31, 2016, 3:51:31 AM3/31/16
to docker-dev
Hi Sabzar,

It looks like you're using logging driver json-file (the default) which means you can execute 
  docker inspect --format='{{.LogPath}}' $INSTANCE_ID
to find out where the log file is.

You can then truncate the file (or delete it _and_ restart the container to recreate it).

As one-liner you could execute  
  sudo sh -c ": > $(docker inspect --format='{{.LogPath}}' $INSTANCE_ID)"
to truncate it.
Some systems also have the 'truncate' command, which allows you to 'truncate -s0 $FILE'.

$INSTANCE_ID can be the long id, short id or just the name of the container.

Obviously it's been pointed out that this is not the best way to do log management, but it's the answer to your question :)

Sabzar Ahmad

unread,
Mar 31, 2016, 6:10:11 AM3/31/16
to docker-dev
Thanks Edwin ,

When I run the command  docker inspect --format='{{.LogPath}}' $INSTANCE_ID I can see below path and file name.

/mnt/sda1/var/lib/docker/containers/083c181cb9a182435cd8eef136c0cb1a0caeb2ebb285833702822bca9e9da53e/083c181cb9a182435cd8eef136c0cb1a0caeb2ebb285833702822bca9e9da53e-json.log

But when I run sh -c ": > $(docker inspect --format='{{.LogPath}}' $INSTANCE_ID)" it is showing no such file or directory.


Also when I to point  /mnt,  I cannot see any thing in this folder.



Edwin Hermans

unread,
Mar 31, 2016, 8:53:32 AM3/31/16
to docker-dev
So /mnt/sda1 doesn't exist either? Could it be you mounted something over /mnt after you mounted /mnt/sda1?

With the command
  sudo lsof -f -p $(pgrep -f "docker daemon") | grep "\.log"
you can check which files containing ".log" the docker daemon has opened, check if the log file mentioned above is listed there.

If the file is still not to be found, but 'docker logs $INSTANCE_ID' still outputs some log lines, then the only thing left I can think of is using strace, which seems a bit overkill.
Stopping, removing and starting the container would then be the easier solution.

Figuring out why a file is referenced which doesn't exist warrants some investigation into the setup of your host.

-- 
Edwin

Sabzar Ahmad

unread,
Apr 1, 2016, 6:09:23 AM4/1/16
to docker-dev
Thanks Edwin,
I can't understand why it is so difficult to found out docker logs.

When I run the bellow command 
lsof -f -p $(pgrep -f "docker daemon") | grep "\.log"
out put is coming as below.

bash: pgrep: command not found
bash: lsof: command not found


Do we need to mount explicitly  /mnt/sda1 ?. As you have mentioned like "mounted /mnt/sda1?". 




Sabzar Ahmad


Sabzar Ahmad

unread,
Apr 1, 2016, 7:57:23 AM4/1/16
to docker-dev
Thanks Edwin for your help,

I was checking the docker log file path at Docker Terminal. which is wrong. 
As I am using VM VirtualBox, On windows. I have search it on VM. 
I am able to locate the docker log file and remove contents of it with the below commands.

To find out where the log file is :   docker inspect --format='{{.LogPath}}' $INSTANCE_ID
.

For cleaning the logs :             sh -c ": > $(docker inspect --format='{{.LogPath}}' $INSTANCE_ID)"



Thanks & Regards
Sabzar Ahmad

Reply all
Reply to author
Forward
0 new messages