docker container space usage

Problem

I kept getting warnings that my root directory was running out of space in the morning. When I ran my disc analyzer as the standard user I wasn’t getting what was using up the space.

Solution

  • Run the disc analyzer as the root user

whiscard@whiscardz ~ $ sudo baobab

Selection_999(276)

  • Then from there I could see it was my docker containers were the culprits
  • I then ran the docker command to see which container was using up space. I started with docker ps -s:

whiscard@whiscardz ~ $ docker ps -s

demo 14.2 GB (virtual 14.8 GB)
d4a5e3d20785 e21d76c561a9 "/run.sh" 11 months ago Up 15 minutes 0.0.0.0:9998->8080/tcp
bk 27.8 GB (virtual 28.4 GB)
3c14f993d2df e21d76c561a9 "/run.sh" 15 months ago Up 16 minutes 0.0.0.0:9996->8080/tcp
sandbox 2.59 GB (virtual 3.24 GB)
683d77e29c69 e21d76c561a9 "/run.sh" 15 months ago Up 16 minutes 0.0.0.0:9997->8080/tcp
emr 2.29 GB (virtual 2.94 GB)
70f8aa5954e4 mysql/mysql-server:5.6 "/entrypoint.sh --..." 16 months ago Up 16 minutes 0.0.0.0:3307->3306/tcp
mysql 1.42 GB (virtual 1.64 GB)
whiscard@whiscardz ~ $

  • I then ran the docker system df -v to get even more granular breakdown:

whiscard@whiscardz ~ $ docker system df -v
Images space usage:

REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE
CONTAINERS
docker latest 33269005f91a 4 months ago 988.9 MB 557.5 MB 431.4 MB
1

Containers space usage:

CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
e1626eb772fc 33269005f91a "/run.sh" 1 122 MB 4 months ago Exited (130) 4 months ago p
latform2.x

Local Volumes space usage:

VOLUME NAME LINKS SIZE
2c8f73ae0dd05f69a7991502f4311d0642a082309eb19e0318f4d721c8360c20 1 103.7 MB

  • Then I got into one of the containers and checked what was taking up so much space

whiscard@whiscardz ~ $ docker exec -it bk bash
root@d4a5e3d20785:/usr/local/tomcat# cd
root@d4a5e3d20785:~# df -h

root@d4a5e3d20785:~# cd /
root@d4a5e3d20785:/# du -h | grep G

30G ./usr/local/tomcat/temp
30G ./usr/local/tomcat
30G ./usr/local
30G ./usr

  • As you can see, tomcat’s temp directory was the issue

References

Comment 1 Docker – How to analyze a container’s disk usage?

Comment 2 Docker – How to analyze a container’s disk usage?

virtualbox commandline options

Update 2019-01-15

Problem

Also needed to delete virtual box images that were not being used via the command line

Solution

  • First list the vms

$ VBoxManage list vms
"20180126" {00953737-12d0-49eb-a1d2-c749047ccacf}
"1519895285801_90671" {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3}
"1522057779833_1088" {87021084-3202-4131-8f9c-5839774140a8}
  • Use the unregistervm flag along with the –delete option to delete the vm and it’s associated files.

$ vboxmanage unregistervm {ac82a1dc-ef6b-40de-8a35-ce4dbee3e6e3} --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Problem

Needed a way to be able to start and stop GuestOS on virtualbox using the commandline.

Solution

  • First list the vms

$ VBoxManage list runningvms
"academy_default_1522238466753_84362" {3a36e205-e8e2-4a96-b9c3-9f76f2ad17e5}

Here are some more options that can be used with the list command. NB If your vm was started with a specific user then running list without switching to the user that started the vm causes the result to be blank:


~$ vboxmanage list
Usage:

VBoxManage list [--long|-l] [--sorted|-s] vms|runningvms|ostypes|hostdvds|hostfloppies|
intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|
hostinfo|hostcpuids|hddbackends|hdds|dvds|floppies|
usbhost|usbfilters|systemproperties|extpacks|
groups|webcams|screenshotformats

  • Then shutdown the vms

~$ vboxmanage controlvm "academy_default_1522238466753_84362" poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
:~$ vboxmanage list runningvms
:~$

References

vboxmanage command line options

How to safely shutdown Guest OS in VirtualBox using command line

How to automatically start and shut down VirtualBox machines?

VBoxManage control and manage Virtualbox from command line

How to run VirtualBox virtual machines from the command line

VBoxManage registervm/unregistervm or delete vm