sickcodes / Docker-OSX

Run macOS VM in a Docker! Run near native OSX-KVM in Docker! X11 Forwarding! CI/CD for OS X Security Research! Docker mac Containers.
https://hub.docker.com/r/sickcodes/docker-osx
GNU General Public License v3.0
36.13k stars 1.78k forks source link

Disk usage grows uncontrollably #674

Open ju-li opened 1 year ago

ju-li commented 1 year ago

Hi everyone,

Does this happen to you too?

I ran docker ps -a --size yesterday: image

And this was ran today: image

After about 24h, the size of the containers have grown by 2GB

I am not doing anything with the containers. Not installing or downloading anything. Just running them in the background.

Why is this happening?

The docker command that I'm using is:

    docker run -d --name macos2 \
    --device /dev/kvm \
    -p 50923:10022 \
    -p 5998:5999 \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e "DISPLAY=${DISPLAY:-:0.0}" \
    -e EXTRA="-display none -vnc 0.0.0.0:99" \
    -e GENERATE_SPECIFIC=true \
    -e DEVICE_MODEL="iMacPro1,1" \
    -e SERIAL="{{SERIAL}}" \
    -e BOARD_SERIAL="{{BOARD SERIAL}}" \
    -e UUID="{{UUID}}" \
    -e MAC_ADDRESS="{{MAC}}" \
    sickcodes/docker-osx:mojave

Note: I replaced the serials with {{}} placeholders

OS related issued, please help us identify the issue by posting the output of this

uname -a \ ; echo "${DISPLAY}" \ ; echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs \ ; grep NAME /etc/os-release \ ; df -h . \ ; qemu-system-x86_64 --version \ ; libvirtd --version \ ; free -mh \ ; nproc \ ; egrep -c '(svm|vmx)' /proc/cpuinfo \ ; ls -lha /dev/kvm \ ; ls -lha /tmp/.X11-unix/ \ ; ps aux | grep dockerd \ ; docker ps | grep osx \ ; grep "docker|kvm|virt" /etc/group

Output is as follows:

1
NAME="Ubuntu"
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/vgBUF164-root  467G   78G  366G  18% /
QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.27)
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
libvirtd (libvirt) 6.0.0
              total        used        free      shared  buff/cache   available
Mem:           62Gi       7.2Gi       354Mi       1.0Mi        55Gi        55Gi
Swap:         975Mi       3.0Mi       972Mi
24
24
crw-rw---- 1 root kvm 10, 232 Jun 22 18:08 /dev/kvm
total 8.0K
drwxrwxrwt  2 root root 4.0K Jun 21 17:43 .
drwxrwxrwt 13 root root 4.0K Jun 28 14:49 ..
root        3271  0.0  0.1 3158188 86420 ?       Ssl  Jun21   4:18 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
juli      101652  0.0  0.0   9368  2128 pts/0    S+   16:19   0:00 grep --color=auto dockerd
26a006694c7c   sickcodes/docker-osx:mojave   "/bin/bash -c 'sudo …"   5 days ago   Up 5 days   0.0.0.0:5998->5999/tcp, :::5998->5999/tcp, 0.0.0.0:50923->10022/tcp, :::50923->10022/tcp   macos2
00de1ca0c66d   sickcodes/docker-osx:mojave   "/bin/bash -c 'sudo …"   6 days ago   Up 6 days   0.0.0.0:5999->5999/tcp, :::5999->5999/tcp, 0.0.0.0:50922->10022/tcp, :::50922->10022/tcp   macos
kvm:x:108:
docker:x:998:juli
libvirt:x:118:juli
libvirt-qemu:x:64055:libvirt-qemu
libvirt-dnsmasq:x:119:
programmrz commented 1 year ago

I'm not sure exactly how the image works, but ANY write from the macOS "vm" will increase the size of the qcow image, until it reaches the size of the virtual disk you have macos installed on. You can resize the macos portion of the disk (I've set mine to 80gb) so the qcow2 image wont expand higher than that.

OriWeiss commented 11 months ago

@programmrz can you please provide instructions on how to do this? I am having the same issue.

ju-li commented 11 months ago

@OriWeiss I think he means in this step: https://github.com/sickcodes/Docker-OSX#additional-boot-instructions-for-when-you-are-creating-your-container

(optional) Create a partition using the unused space to house the OS and your files if you want to limit the capacity. (For Xcode 12 partition at least 60gb.)

I haven't tested it but this sounds like a solution